﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibKetoan;
using doiso;

namespace Ketoan
{
	/// <summary>
	/// Summary description for frmNhapng.
	/// </summary>
	public class frmNhapng : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.Button butMoi;
		private System.Windows.Forms.Button butSua;
		private System.Windows.Forms.Button butLuu;
		private System.Windows.Forms.Button butThem;
		private System.Windows.Forms.Button butXoa;
		private System.Windows.Forms.Button butBoqua;
		private System.Windows.Forms.Button butHuy;
		private System.Windows.Forms.Button butIn;
		private System.Windows.Forms.Button butKetthuc;
		private System.Windows.Forms.Label label21;
		private System.Windows.Forms.Label label22;
		private string s_mmyy,sql,format_sotien,s_sophieu,s_thangqt,user,s_stkdt,s_mmyyhd;
		private int i_userid,i_old,i_songay,itable,lctug_dutoanns;
		private long l_id,l_idct,l_iddongthoi,l_idtim,l_hopdong=0;
		private bool bKhoaso,bNew,bAdmin,bSophieu,bSophieu_nam;
		private AccessData a;
        private DataTable stk_hachtoan = new DataTable();
		private Doisototext doiso=new Doisototext();
		private DataTable dtmtm=new DataTable();
		private DataTable dtll=new DataTable();
		private DataTable dtct=new DataTable();
		private DataTable dttk=new DataTable();
		private DataTable dtold=new DataTable();
		private DataTable dtdt=new DataTable();
		private DataTable dtloai=new DataTable();
		private DataTable dtloaidt=new DataTable();
		private DataTable dtnt=new DataTable();
		private DataTable dtnh=new DataTable();
		private DataTable dtnns=new DataTable();
		private DataSet dsxoa=new DataSet();
		private DataRow r;
		private System.Windows.Forms.TextBox stt;
		private System.Windows.Forms.TextBox find;
		private System.Windows.Forms.CheckBox chkIn;
		private System.Windows.Forms.Label lsokhoan;
		private System.Windows.Forms.ToolTip toolTip1;
		private System.Windows.Forms.Label label35;
		private System.Windows.Forms.NumericUpDown tt;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.Label label37;
		private System.Windows.Forms.Label label38;
		private System.Windows.Forms.Label label43;
		private System.Windows.Forms.ComboBox hoatdong;
		private System.Windows.Forms.ComboBox lctug;
		private MaskedBox.MaskedBox ngayg;
		private MaskedBox.MaskedBox ngaygs;
		private MaskedTextBox.MaskedTextBox ctgs;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.ComboBox chuong;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.ComboBox nghiepvu;
		private System.Windows.Forms.TextBox tknoa;
		private System.Windows.Forms.TextBox ttknoa;
		private System.Windows.Forms.Label label45;
		private System.Windows.Forms.ComboBox tcnkp;
		private System.Windows.Forms.Label label46;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.TextBox ttkcoa;
		private System.Windows.Forms.TextBox tkcoa;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label33;
		private System.Windows.Forms.ComboBox loaibk;
		private System.Windows.Forms.Label label34;
		private System.Windows.Forms.Label label47;
		private System.Windows.Forms.Label label48;
		private System.Windows.Forms.Label label49;
		private System.Windows.Forms.Label label50;
		private System.Windows.Forms.ComboBox lk;
		private System.Windows.Forms.TextBox ttkno;
		private System.Windows.Forms.TextBox tkno;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.Label label16;
		private System.Windows.Forms.TextBox mtmno;
		private System.Windows.Forms.Label label17;
		private MaskedTextBox.MaskedTextBox stien;
		private MaskedTextBox.MaskedTextBox tygia;
		private MaskedTextBox.MaskedTextBox nguyente;
		private System.Windows.Forms.TextBox ttkco;
		private System.Windows.Forms.TextBox mtmco;
		private System.Windows.Forms.ComboBox kmco;
		private System.Windows.Forms.Label label18;
		private System.Windows.Forms.Label label19;
		private System.Windows.Forms.TextBox tkco;
		private System.Windows.Forms.Label label20;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.ComboBox mapt;
		private System.Windows.Forms.Label label23;
		private System.Windows.Forms.Label label24;
		private System.Windows.Forms.ComboBox capphat;
		private System.Windows.Forms.ComboBox ngoaite;
		private System.Windows.Forms.Label label25;
		private System.Windows.Forms.CheckBox tonghop;
		private System.Windows.Forms.Button butBangke;
		private MaskedTextBox.MaskedTextBox diachi;
		private System.Windows.Forms.TextBox hopdong;
		private System.Windows.Forms.Label label26;
		private System.Windows.Forms.ComboBox loaidt;
		private System.Windows.Forms.TextBox tendt;
		private System.Windows.Forms.TextBox madt;
		private System.Windows.Forms.Label label27;
		private System.Windows.Forms.ComboBox cmbSoctg;
		private MaskedTextBox.MaskedTextBox soctg;
		private System.Windows.Forms.TextBox ngayhd;
		private System.Windows.Forms.TextBox thuesuat;
		private System.Windows.Forms.TextBox tienthue;
		private System.Windows.Forms.ComboBox kmno;
		private string s_chuong,s_lk,s_lctug,s_nghiepvu,s_ngayg="",s_ngaygs="",s_ngay="";
		private LibList.List listdt;
		private LibList.List listmtm;
		private System.Windows.Forms.TextBox hoadon;
		private LibList.List liststk;
		private System.Windows.Forms.TextBox stemp;
		private LibList.List listtkno;
		private LibList.List listtkco;
		private int chucnang;
		private long ltknoa,ltkcoa,ltkno,ltkco,lmtmno,lmtmco,lmadt;
		private decimal dstien,dnguyente;
		private System.Windows.Forms.TextBox znguyente;
		private System.Windows.Forms.TextBox zstien;
		private System.Windows.Forms.Label label28;
		private MaskedTextBox.MaskedTextBox sotk;
		private System.Windows.Forms.Label label29;
		private MaskedTextBox.MaskedTextBox tennhno;
		private System.Windows.Forms.Label label30;
		private MaskedTextBox.MaskedTextBox tennhco;
		private System.Windows.Forms.Label label31;
		private System.Windows.Forms.Label label32;
		private MaskedTextBox.MaskedTextBox sotkno;
		private MaskedTextBox.MaskedTextBox sotkco;
		private System.Windows.Forms.TextBox noidunga;
		private System.Windows.Forms.CheckBox chkXml;
		private System.Windows.Forms.ComboBox nhom;
		private System.Windows.Forms.Label label36;
		private System.Windows.Forms.ComboBox kmno3;
		private System.Windows.Forms.ComboBox kmno2;
		private System.Windows.Forms.ComboBox kmno4;
		private System.Windows.Forms.Label label39;
		private System.Windows.Forms.Label label40;
		private System.Windows.Forms.Label label41;
		private System.Windows.Forms.ComboBox kmco3;
		private System.Windows.Forms.ComboBox kmco2;
		private System.Windows.Forms.ComboBox kmco4;
		private System.Windows.Forms.Label label42;
		private System.Windows.Forms.Label label44;
		private System.Windows.Forms.Label label51;
		private System.Windows.Forms.TextBox noidung;
		private System.Windows.Forms.Button butHD;
		private System.Windows.Forms.Label label52;
		private System.Windows.Forms.ComboBox cbnguonns;
        private Label label53;
        private Label label54;
		private DataTable dtht=new DataTable();

		public frmNhapng(AccessData acc,string mmyy,string ngay,string _chuong,string _lk,string _lctug,string _nghiepvu,int _chucnang,int userid,string title,bool admin,int _lctug_dutoanns,long idtim)
		{
			InitializeComponent();
			butBangke.Visible=false;lctug_dutoanns=_lctug_dutoanns;
			a=acc;i_userid=userid;s_mmyy=mmyy;s_ngay=ngay;l_idtim=idtim;
			s_chuong=_chuong;s_lk=_lk;s_lctug=_lctug;s_nghiepvu=_nghiepvu;
			bAdmin=admin;this.Text=title;chucnang=_chucnang;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmNhapng));
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.label8 = new System.Windows.Forms.Label();
            this.label9 = new System.Windows.Forms.Label();
            this.label10 = new System.Windows.Forms.Label();
            this.ngayg = new MaskedBox.MaskedBox();
            this.ngaygs = new MaskedBox.MaskedBox();
            this.tknoa = new System.Windows.Forms.TextBox();
            this.ttknoa = new System.Windows.Forms.TextBox();
            this.hoatdong = new System.Windows.Forms.ComboBox();
            this.lctug = new System.Windows.Forms.ComboBox();
            this.listdt = new LibList.List();
            this.dataGrid1 = new System.Windows.Forms.DataGrid();
            this.label14 = new System.Windows.Forms.Label();
            this.butMoi = new System.Windows.Forms.Button();
            this.butSua = new System.Windows.Forms.Button();
            this.butLuu = new System.Windows.Forms.Button();
            this.butThem = new System.Windows.Forms.Button();
            this.butXoa = new System.Windows.Forms.Button();
            this.butBoqua = new System.Windows.Forms.Button();
            this.butHuy = new System.Windows.Forms.Button();
            this.butIn = new System.Windows.Forms.Button();
            this.butKetthuc = new System.Windows.Forms.Button();
            this.label21 = new System.Windows.Forms.Label();
            this.label22 = new System.Windows.Forms.Label();
            this.znguyente = new System.Windows.Forms.TextBox();
            this.zstien = new System.Windows.Forms.TextBox();
            this.cmbSoctg = new System.Windows.Forms.ComboBox();
            this.stt = new System.Windows.Forms.TextBox();
            this.soctg = new MaskedTextBox.MaskedTextBox();
            this.ctgs = new MaskedTextBox.MaskedTextBox();
            this.find = new System.Windows.Forms.TextBox();
            this.chkIn = new System.Windows.Forms.CheckBox();
            this.lsokhoan = new System.Windows.Forms.Label();
            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.butHD = new System.Windows.Forms.Button();
            this.label35 = new System.Windows.Forms.Label();
            this.tt = new System.Windows.Forms.NumericUpDown();
            this.stien = new MaskedTextBox.MaskedTextBox();
            this.tygia = new MaskedTextBox.MaskedTextBox();
            this.label37 = new System.Windows.Forms.Label();
            this.label38 = new System.Windows.Forms.Label();
            this.nguyente = new MaskedTextBox.MaskedTextBox();
            this.label43 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.chuong = new System.Windows.Forms.ComboBox();
            this.label7 = new System.Windows.Forms.Label();
            this.nghiepvu = new System.Windows.Forms.ComboBox();
            this.label45 = new System.Windows.Forms.Label();
            this.tcnkp = new System.Windows.Forms.ComboBox();
            this.label46 = new System.Windows.Forms.Label();
            this.diachi = new MaskedTextBox.MaskedTextBox();
            this.label11 = new System.Windows.Forms.Label();
            this.ttkcoa = new System.Windows.Forms.TextBox();
            this.tkcoa = new System.Windows.Forms.TextBox();
            this.label12 = new System.Windows.Forms.Label();
            this.hopdong = new System.Windows.Forms.TextBox();
            this.label33 = new System.Windows.Forms.Label();
            this.loaibk = new System.Windows.Forms.ComboBox();
            this.label34 = new System.Windows.Forms.Label();
            this.hoadon = new System.Windows.Forms.TextBox();
            this.label47 = new System.Windows.Forms.Label();
            this.ngayhd = new System.Windows.Forms.TextBox();
            this.label48 = new System.Windows.Forms.Label();
            this.label49 = new System.Windows.Forms.Label();
            this.thuesuat = new System.Windows.Forms.TextBox();
            this.tienthue = new System.Windows.Forms.TextBox();
            this.label50 = new System.Windows.Forms.Label();
            this.lk = new System.Windows.Forms.ComboBox();
            this.ttkno = new System.Windows.Forms.TextBox();
            this.tkno = new System.Windows.Forms.TextBox();
            this.label13 = new System.Windows.Forms.Label();
            this.label16 = new System.Windows.Forms.Label();
            this.mtmno = new System.Windows.Forms.TextBox();
            this.label17 = new System.Windows.Forms.Label();
            this.kmno = new System.Windows.Forms.ComboBox();
            this.ttkco = new System.Windows.Forms.TextBox();
            this.mtmco = new System.Windows.Forms.TextBox();
            this.kmco = new System.Windows.Forms.ComboBox();
            this.label18 = new System.Windows.Forms.Label();
            this.label19 = new System.Windows.Forms.Label();
            this.tkco = new System.Windows.Forms.TextBox();
            this.label20 = new System.Windows.Forms.Label();
            this.label15 = new System.Windows.Forms.Label();
            this.mapt = new System.Windows.Forms.ComboBox();
            this.label23 = new System.Windows.Forms.Label();
            this.label24 = new System.Windows.Forms.Label();
            this.capphat = new System.Windows.Forms.ComboBox();
            this.ngoaite = new System.Windows.Forms.ComboBox();
            this.label25 = new System.Windows.Forms.Label();
            this.tonghop = new System.Windows.Forms.CheckBox();
            this.butBangke = new System.Windows.Forms.Button();
            this.label26 = new System.Windows.Forms.Label();
            this.loaidt = new System.Windows.Forms.ComboBox();
            this.tendt = new System.Windows.Forms.TextBox();
            this.madt = new System.Windows.Forms.TextBox();
            this.label27 = new System.Windows.Forms.Label();
            this.listmtm = new LibList.List();
            this.liststk = new LibList.List();
            this.stemp = new System.Windows.Forms.TextBox();
            this.listtkno = new LibList.List();
            this.listtkco = new LibList.List();
            this.noidung = new System.Windows.Forms.TextBox();
            this.label28 = new System.Windows.Forms.Label();
            this.sotk = new MaskedTextBox.MaskedTextBox();
            this.sotkno = new MaskedTextBox.MaskedTextBox();
            this.label29 = new System.Windows.Forms.Label();
            this.tennhno = new MaskedTextBox.MaskedTextBox();
            this.label30 = new System.Windows.Forms.Label();
            this.sotkco = new MaskedTextBox.MaskedTextBox();
            this.tennhco = new MaskedTextBox.MaskedTextBox();
            this.label31 = new System.Windows.Forms.Label();
            this.label32 = new System.Windows.Forms.Label();
            this.noidunga = new System.Windows.Forms.TextBox();
            this.chkXml = new System.Windows.Forms.CheckBox();
            this.nhom = new System.Windows.Forms.ComboBox();
            this.label36 = new System.Windows.Forms.Label();
            this.kmno3 = new System.Windows.Forms.ComboBox();
            this.kmno2 = new System.Windows.Forms.ComboBox();
            this.kmno4 = new System.Windows.Forms.ComboBox();
            this.label39 = new System.Windows.Forms.Label();
            this.label40 = new System.Windows.Forms.Label();
            this.label41 = new System.Windows.Forms.Label();
            this.kmco3 = new System.Windows.Forms.ComboBox();
            this.kmco2 = new System.Windows.Forms.ComboBox();
            this.kmco4 = new System.Windows.Forms.ComboBox();
            this.label42 = new System.Windows.Forms.Label();
            this.label44 = new System.Windows.Forms.Label();
            this.label51 = new System.Windows.Forms.Label();
            this.label52 = new System.Windows.Forms.Label();
            this.cbnguonns = new System.Windows.Forms.ComboBox();
            this.label53 = new System.Windows.Forms.Label();
            this.label54 = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.tt)).BeginInit();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label1.Location = new System.Drawing.Point(773, 4);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(56, 23);
            this.label1.TabIndex = 4;
            this.label1.Text = "Số phiếu :";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label2
            // 
            this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label2.Location = new System.Drawing.Point(967, 4);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(48, 23);
            this.label2.TabIndex = 7;
            this.label2.Text = "Ngày :";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(136, 25);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(96, 23);
            this.label3.TabIndex = 11;
            this.label3.Text = "Chứng từ ghi sổ :";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(-13, 25);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(96, 23);
            this.label4.TabIndex = 9;
            this.label4.Text = "Ngày hạch toán :";
            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label5
            // 
            this.label5.Location = new System.Drawing.Point(3, 116);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(80, 23);
            this.label5.TabIndex = 28;
            this.label5.Text = "Tài khoản nợ :";
            this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label8
            // 
            this.label8.Location = new System.Drawing.Point(168, 48);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(64, 23);
            this.label8.TabIndex = 19;
            this.label8.Text = "Nội dung :";
            this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label9
            // 
            this.label9.Location = new System.Drawing.Point(168, 4);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(64, 23);
            this.label9.TabIndex = 130;
            this.label9.Text = "Hoạt động :";
            this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label10
            // 
            this.label10.Location = new System.Drawing.Point(335, 4);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(79, 23);
            this.label10.TabIndex = 2;
            this.label10.Text = "Loại chứng từ :";
            this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // ngayg
            // 
            this.ngayg.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.ngayg.BackColor = System.Drawing.SystemColors.HighlightText;
            this.ngayg.Enabled = false;
            this.ngayg.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ngayg.Location = new System.Drawing.Point(1017, 4);
            this.ngayg.Mask = "##/##/####";
            this.ngayg.MaxLength = 10;
            this.ngayg.Name = "ngayg";
            this.ngayg.Size = new System.Drawing.Size(64, 21);
            this.ngayg.TabIndex = 8;
            this.ngayg.Text = "  /  /    ";
            this.ngayg.Validated += new System.EventHandler(this.ngayg_Validated);
            // 
            // ngaygs
            // 
            this.ngaygs.BackColor = System.Drawing.SystemColors.HighlightText;
            this.ngaygs.Enabled = false;
            this.ngaygs.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ngaygs.Location = new System.Drawing.Point(83, 27);
            this.ngaygs.Mask = "##/##/####";
            this.ngaygs.MaxLength = 10;
            this.ngaygs.Name = "ngaygs";
            this.ngaygs.Size = new System.Drawing.Size(64, 21);
            this.ngaygs.TabIndex = 10;
            this.ngaygs.Text = "  /  /    ";
            this.ngaygs.Validated += new System.EventHandler(this.ngaygs_Validated);
            // 
            // tknoa
            // 
            this.tknoa.BackColor = System.Drawing.SystemColors.HighlightText;
            this.tknoa.Enabled = false;
            this.tknoa.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tknoa.Location = new System.Drawing.Point(83, 119);
            this.tknoa.Name = "tknoa";
            this.tknoa.Size = new System.Drawing.Size(69, 21);
            this.tknoa.TabIndex = 29;
            this.tknoa.TextChanged += new System.EventHandler(this.tknoa_TextChanged);
            this.tknoa.Validated += new System.EventHandler(this.tknoa_Validated);
            this.tknoa.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tknoa_KeyDown);
            // 
            // ttknoa
            // 
            this.ttknoa.BackColor = System.Drawing.SystemColors.HighlightText;
            this.ttknoa.Enabled = false;
            this.ttknoa.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ttknoa.Location = new System.Drawing.Point(153, 119);
            this.ttknoa.Name = "ttknoa";
            this.ttknoa.Size = new System.Drawing.Size(232, 21);
            this.ttknoa.TabIndex = 30;
            // 
            // hoatdong
            // 
            this.hoatdong.BackColor = System.Drawing.SystemColors.HighlightText;
            this.hoatdong.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.hoatdong.Enabled = false;
            this.hoatdong.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.hoatdong.Location = new System.Drawing.Point(232, 4);
            this.hoatdong.Name = "hoatdong";
            this.hoatdong.Size = new System.Drawing.Size(107, 21);
            this.hoatdong.TabIndex = 1;
            this.hoatdong.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // lctug
            // 
            this.lctug.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.lctug.BackColor = System.Drawing.SystemColors.HighlightText;
            this.lctug.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.lctug.Enabled = false;
            this.lctug.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lctug.Location = new System.Drawing.Point(408, 4);
            this.lctug.Name = "lctug";
            this.lctug.Size = new System.Drawing.Size(342, 21);
            this.lctug.TabIndex = 3;
            this.lctug.SelectedIndexChanged += new System.EventHandler(this.lctug_SelectedIndexChanged);
            this.lctug.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // listdt
            // 
            this.listdt.BackColor = System.Drawing.SystemColors.Info;
            this.listdt.ColumnCount = 0;
            this.listdt.Location = new System.Drawing.Point(590, 554);
            this.listdt.MatchBufferTimeOut = 1000;
            this.listdt.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
            this.listdt.Name = "listdt";
            this.listdt.Size = new System.Drawing.Size(0, 4);
            this.listdt.TabIndex = 100;
            this.listdt.TextIndex = -1;
            this.listdt.TextMember = null;
            this.listdt.ValueIndex = -1;
            this.listdt.Visible = false;
            this.listdt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listdt_KeyDown);
            // 
            // dataGrid1
            // 
            this.dataGrid1.AlternatingBackColor = System.Drawing.Color.Lavender;
            this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.dataGrid1.BackColor = System.Drawing.Color.WhiteSmoke;
            this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.Control;
            this.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.Control;
            this.dataGrid1.CaptionFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.dataGrid1.CaptionForeColor = System.Drawing.Color.MidnightBlue;
            this.dataGrid1.DataMember = "";
            this.dataGrid1.FlatMode = true;
            this.dataGrid1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.dataGrid1.ForeColor = System.Drawing.Color.MidnightBlue;
            this.dataGrid1.GridLineColor = System.Drawing.Color.Gainsboro;
            this.dataGrid1.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
            this.dataGrid1.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
            this.dataGrid1.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
            this.dataGrid1.LinkColor = System.Drawing.Color.Teal;
            this.dataGrid1.Location = new System.Drawing.Point(8, 192);
            this.dataGrid1.Name = "dataGrid1";
            this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
            this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
            this.dataGrid1.ReadOnly = true;
            this.dataGrid1.RowHeaderWidth = 10;
            this.dataGrid1.SelectionBackColor = System.Drawing.Color.CadetBlue;
            this.dataGrid1.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
            this.dataGrid1.Size = new System.Drawing.Size(1073, 160);
            this.dataGrid1.TabIndex = 190;
            this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
            // 
            // label14
            // 
            this.label14.ForeColor = System.Drawing.SystemColors.ActiveCaption;
            this.label14.Location = new System.Drawing.Point(288, 185);
            this.label14.Name = "label14";
            this.label14.Size = new System.Drawing.Size(8, 23);
            this.label14.TabIndex = 44;
            this.label14.Text = "%";
            this.label14.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // butMoi
            // 
            this.butMoi.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butMoi.Image = ((System.Drawing.Image)(resources.GetObject("butMoi.Image")));
            this.butMoi.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butMoi.Location = new System.Drawing.Point(284, 491);
            this.butMoi.Name = "butMoi";
            this.butMoi.Size = new System.Drawing.Size(60, 25);
            this.butMoi.TabIndex = 96;
            this.butMoi.Text = "      &Mới";
            this.butMoi.Click += new System.EventHandler(this.butMoi_Click);
            // 
            // butSua
            // 
            this.butSua.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butSua.Image = ((System.Drawing.Image)(resources.GetObject("butSua.Image")));
            this.butSua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butSua.Location = new System.Drawing.Point(346, 491);
            this.butSua.Name = "butSua";
            this.butSua.Size = new System.Drawing.Size(60, 25);
            this.butSua.TabIndex = 97;
            this.butSua.Text = "     &Sửa";
            this.butSua.Click += new System.EventHandler(this.butSua_Click);
            // 
            // butLuu
            // 
            this.butLuu.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butLuu.Enabled = false;
            this.butLuu.Image = ((System.Drawing.Image)(resources.GetObject("butLuu.Image")));
            this.butLuu.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butLuu.Location = new System.Drawing.Point(408, 491);
            this.butLuu.Name = "butLuu";
            this.butLuu.Size = new System.Drawing.Size(60, 25);
            this.butLuu.TabIndex = 94;
            this.butLuu.Text = "     &Lưu";
            this.butLuu.Click += new System.EventHandler(this.butLuu_Click);
            // 
            // butThem
            // 
            this.butThem.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butThem.Enabled = false;
            this.butThem.Image = ((System.Drawing.Image)(resources.GetObject("butThem.Image")));
            this.butThem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butThem.Location = new System.Drawing.Point(470, 491);
            this.butThem.Name = "butThem";
            this.butThem.Size = new System.Drawing.Size(60, 25);
            this.butThem.TabIndex = 92;
            this.butThem.Text = "&Thêm";
            this.butThem.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butThem.Click += new System.EventHandler(this.butThem_Click);
            // 
            // butXoa
            // 
            this.butXoa.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butXoa.Enabled = false;
            this.butXoa.Image = ((System.Drawing.Image)(resources.GetObject("butXoa.Image")));
            this.butXoa.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butXoa.Location = new System.Drawing.Point(532, 491);
            this.butXoa.Name = "butXoa";
            this.butXoa.Size = new System.Drawing.Size(60, 25);
            this.butXoa.TabIndex = 93;
            this.butXoa.Text = "     &Xóa";
            this.butXoa.Click += new System.EventHandler(this.butXoa_Click);
            // 
            // butBoqua
            // 
            this.butBoqua.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butBoqua.Enabled = false;
            this.butBoqua.Image = ((System.Drawing.Image)(resources.GetObject("butBoqua.Image")));
            this.butBoqua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butBoqua.Location = new System.Drawing.Point(594, 491);
            this.butBoqua.Name = "butBoqua";
            this.butBoqua.Size = new System.Drawing.Size(60, 25);
            this.butBoqua.TabIndex = 95;
            this.butBoqua.Text = "&Bỏ qua";
            this.butBoqua.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butBoqua.Click += new System.EventHandler(this.butBoqua_Click);
            // 
            // butHuy
            // 
            this.butHuy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butHuy.Image = ((System.Drawing.Image)(resources.GetObject("butHuy.Image")));
            this.butHuy.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butHuy.Location = new System.Drawing.Point(656, 491);
            this.butHuy.Name = "butHuy";
            this.butHuy.Size = new System.Drawing.Size(60, 25);
            this.butHuy.TabIndex = 98;
            this.butHuy.Text = "     &Hủy";
            this.butHuy.Click += new System.EventHandler(this.butHuy_Click);
            // 
            // butIn
            // 
            this.butIn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butIn.Image = ((System.Drawing.Image)(resources.GetObject("butIn.Image")));
            this.butIn.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butIn.Location = new System.Drawing.Point(718, 491);
            this.butIn.Name = "butIn";
            this.butIn.Size = new System.Drawing.Size(60, 25);
            this.butIn.TabIndex = 99;
            this.butIn.Text = "      &In";
            this.butIn.Click += new System.EventHandler(this.butIn_Click);
            // 
            // butKetthuc
            // 
            this.butKetthuc.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butKetthuc.Image = ((System.Drawing.Image)(resources.GetObject("butKetthuc.Image")));
            this.butKetthuc.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butKetthuc.Location = new System.Drawing.Point(780, 491);
            this.butKetthuc.Name = "butKetthuc";
            this.butKetthuc.Size = new System.Drawing.Size(70, 25);
            this.butKetthuc.TabIndex = 100;
            this.butKetthuc.Text = "&Kết thúc";
            this.butKetthuc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butKetthuc.Click += new System.EventHandler(this.butKetthuc_Click);
            // 
            // label21
            // 
            this.label21.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label21.Location = new System.Drawing.Point(608, 341);
            this.label21.Name = "label21";
            this.label21.Size = new System.Drawing.Size(64, 23);
            this.label21.TabIndex = 93;
            this.label21.Text = "Tổng tiền :";
            this.label21.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label22
            // 
            this.label22.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label22.Location = new System.Drawing.Point(368, 341);
            this.label22.Name = "label22";
            this.label22.Size = new System.Drawing.Size(120, 23);
            this.label22.TabIndex = 97;
            this.label22.Text = "Nguyên tệ :";
            this.label22.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // znguyente
            // 
            this.znguyente.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.znguyente.BackColor = System.Drawing.SystemColors.HighlightText;
            this.znguyente.Enabled = false;
            this.znguyente.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.znguyente.Location = new System.Drawing.Point(488, 341);
            this.znguyente.Name = "znguyente";
            this.znguyente.Size = new System.Drawing.Size(120, 21);
            this.znguyente.TabIndex = 95;
            this.znguyente.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            // 
            // zstien
            // 
            this.zstien.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.zstien.BackColor = System.Drawing.SystemColors.HighlightText;
            this.zstien.Enabled = false;
            this.zstien.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.zstien.Location = new System.Drawing.Point(670, 341);
            this.zstien.Name = "zstien";
            this.zstien.Size = new System.Drawing.Size(409, 21);
            this.zstien.TabIndex = 96;
            this.zstien.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            // 
            // cmbSoctg
            // 
            this.cmbSoctg.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.cmbSoctg.BackColor = System.Drawing.SystemColors.HighlightText;
            this.cmbSoctg.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cmbSoctg.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmbSoctg.Location = new System.Drawing.Point(826, 4);
            this.cmbSoctg.Name = "cmbSoctg";
            this.cmbSoctg.Size = new System.Drawing.Size(153, 21);
            this.cmbSoctg.TabIndex = 6;
            this.cmbSoctg.SelectedIndexChanged += new System.EventHandler(this.cmbSophieu_SelectedIndexChanged);
            this.cmbSoctg.KeyDown += new System.Windows.Forms.KeyEventHandler(this.cmbSophieu_KeyDown);
            // 
            // stt
            // 
            this.stt.Enabled = false;
            this.stt.Location = new System.Drawing.Point(64, 240);
            this.stt.Name = "stt";
            this.stt.Size = new System.Drawing.Size(40, 20);
            this.stt.TabIndex = 91;
            // 
            // soctg
            // 
            this.soctg.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.soctg.BackColor = System.Drawing.SystemColors.HighlightText;
            this.soctg.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.soctg.Enabled = false;
            this.soctg.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.soctg.Location = new System.Drawing.Point(875, 4);
            this.soctg.Masked = MaskedTextBox.MaskedTextBox.Mask.None;
            this.soctg.Name = "soctg";
            this.soctg.Size = new System.Drawing.Size(104, 21);
            this.soctg.TabIndex = 5;
            this.soctg.Validated += new System.EventHandler(this.sophieu_Validated);
            // 
            // ctgs
            // 
            this.ctgs.BackColor = System.Drawing.SystemColors.HighlightText;
            this.ctgs.Enabled = false;
            this.ctgs.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ctgs.Location = new System.Drawing.Point(232, 27);
            this.ctgs.Masked = MaskedTextBox.MaskedTextBox.Mask.None;
            this.ctgs.MaxLength = 50;
            this.ctgs.Name = "ctgs";
            this.ctgs.Size = new System.Drawing.Size(107, 21);
            this.ctgs.TabIndex = 12;
            // 
            // find
            // 
            this.find.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.find.BackColor = System.Drawing.SystemColors.HighlightText;
            this.find.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.find.ForeColor = System.Drawing.Color.Red;
            this.find.Location = new System.Drawing.Point(616, 187);
            this.find.Name = "find";
            this.find.Size = new System.Drawing.Size(465, 21);
            this.find.TabIndex = 89;
            this.find.Text = "Tìm kiếm";
            this.find.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.find.TextChanged += new System.EventHandler(this.find_TextChanged);
            this.find.Enter += new System.EventHandler(this.find_Enter);
            // 
            // chkIn
            // 
            this.chkIn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.chkIn.Location = new System.Drawing.Point(983, 484);
            this.chkIn.Name = "chkIn";
            this.chkIn.Size = new System.Drawing.Size(112, 16);
            this.chkIn.TabIndex = 98;
            this.chkIn.Text = "Xem trước khi in";
            // 
            // lsokhoan
            // 
            this.lsokhoan.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.lsokhoan.Location = new System.Drawing.Point(414, 556);
            this.lsokhoan.Name = "lsokhoan";
            this.lsokhoan.Size = new System.Drawing.Size(0, 0);
            this.lsokhoan.TabIndex = 92;
            this.lsokhoan.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.lsokhoan.Visible = false;
            // 
            // butHD
            // 
            this.butHD.Enabled = false;
            this.butHD.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butHD.Image = ((System.Drawing.Image)(resources.GetObject("butHD.Image")));
            this.butHD.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butHD.Location = new System.Drawing.Point(282, 165);
            this.butHD.Name = "butHD";
            this.butHD.Size = new System.Drawing.Size(30, 21);
            this.butHD.TabIndex = 191;
            this.toolTip1.SetToolTip(this.butHD, "Chọn hợp đồng thanh toán");
            this.butHD.Click += new System.EventHandler(this.butHD_Click);
            // 
            // label35
            // 
            this.label35.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label35.Location = new System.Drawing.Point(3, 364);
            this.label35.Name = "label35";
            this.label35.Size = new System.Drawing.Size(80, 23);
            this.label35.TabIndex = 47;
            this.label35.Text = "Số thứ tự :";
            this.label35.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // tt
            // 
            this.tt.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.tt.BackColor = System.Drawing.SystemColors.HighlightText;
            this.tt.Enabled = false;
            this.tt.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tt.Location = new System.Drawing.Point(83, 364);
            this.tt.Maximum = new decimal(new int[] {
            999,
            0,
            0,
            0});
            this.tt.Name = "tt";
            this.tt.Size = new System.Drawing.Size(40, 21);
            this.tt.TabIndex = 48;
            this.tt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // stien
            // 
            this.stien.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.stien.BackColor = System.Drawing.SystemColors.HighlightText;
            this.stien.Enabled = false;
            this.stien.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.stien.Location = new System.Drawing.Point(672, 457);
            this.stien.Masked = MaskedTextBox.MaskedTextBox.Mask.None;
            this.stien.Name = "stien";
            this.stien.Size = new System.Drawing.Size(407, 21);
            this.stien.TabIndex = 90;
            this.stien.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.stien.Validated += new System.EventHandler(this.stien_Validated);
            // 
            // tygia
            // 
            this.tygia.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.tygia.BackColor = System.Drawing.SystemColors.HighlightText;
            this.tygia.Enabled = false;
            this.tygia.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tygia.Location = new System.Drawing.Point(344, 457);
            this.tygia.Masked = MaskedTextBox.MaskedTextBox.Mask.None;
            this.tygia.Name = "tygia";
            this.tygia.Size = new System.Drawing.Size(80, 21);
            this.tygia.TabIndex = 86;
            this.tygia.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            // 
            // label37
            // 
            this.label37.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label37.Location = new System.Drawing.Point(288, 456);
            this.label37.Name = "label37";
            this.label37.Size = new System.Drawing.Size(56, 23);
            this.label37.TabIndex = 85;
            this.label37.Text = "Tỷ giá :";
            this.label37.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label38
            // 
            this.label38.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label38.Location = new System.Drawing.Point(616, 457);
            this.label38.Name = "label38";
            this.label38.Size = new System.Drawing.Size(56, 23);
            this.label38.TabIndex = 89;
            this.label38.Text = "Số tiền :";
            this.label38.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // nguyente
            // 
            this.nguyente.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.nguyente.BackColor = System.Drawing.SystemColors.HighlightText;
            this.nguyente.Enabled = false;
            this.nguyente.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.nguyente.Location = new System.Drawing.Point(488, 457);
            this.nguyente.Masked = MaskedTextBox.MaskedTextBox.Mask.None;
            this.nguyente.Name = "nguyente";
            this.nguyente.Size = new System.Drawing.Size(120, 21);
            this.nguyente.TabIndex = 88;
            this.nguyente.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.nguyente.Validated += new System.EventHandler(this.nguyente_Validated);
            // 
            // label43
            // 
            this.label43.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label43.Location = new System.Drawing.Point(408, 457);
            this.label43.Name = "label43";
            this.label43.Size = new System.Drawing.Size(80, 23);
            this.label43.TabIndex = 87;
            this.label43.Text = "Nguyên tệ :";
            this.label43.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label6
            // 
            this.label6.Location = new System.Drawing.Point(320, 25);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(0, 0);
            this.label6.TabIndex = 13;
            this.label6.Text = "Chương :";
            this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // chuong
            // 
            this.chuong.BackColor = System.Drawing.SystemColors.HighlightText;
            this.chuong.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.chuong.Enabled = false;
            this.chuong.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.chuong.Location = new System.Drawing.Point(378, 27);
            this.chuong.Name = "chuong";
            this.chuong.Size = new System.Drawing.Size(0, 21);
            this.chuong.TabIndex = 14;
            this.chuong.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label7
            // 
            this.label7.Location = new System.Drawing.Point(343, 25);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(64, 23);
            this.label7.TabIndex = 15;
            this.label7.Text = "Nghiệp vụ :";
            this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // nghiepvu
            // 
            this.nghiepvu.BackColor = System.Drawing.SystemColors.HighlightText;
            this.nghiepvu.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.nghiepvu.Enabled = false;
            this.nghiepvu.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.nghiepvu.Location = new System.Drawing.Point(408, 27);
            this.nghiepvu.Name = "nghiepvu";
            this.nghiepvu.Size = new System.Drawing.Size(342, 21);
            this.nghiepvu.TabIndex = 16;
            this.nghiepvu.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label45
            // 
            this.label45.Location = new System.Drawing.Point(-5, 48);
            this.label45.Name = "label45";
            this.label45.Size = new System.Drawing.Size(88, 23);
            this.label45.TabIndex = 17;
            this.label45.Text = "Nguồn kinh phí :";
            this.label45.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // tcnkp
            // 
            this.tcnkp.BackColor = System.Drawing.SystemColors.HighlightText;
            this.tcnkp.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.tcnkp.Enabled = false;
            this.tcnkp.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tcnkp.Location = new System.Drawing.Point(83, 50);
            this.tcnkp.Name = "tcnkp";
            this.tcnkp.Size = new System.Drawing.Size(93, 21);
            this.tcnkp.TabIndex = 18;
            this.tcnkp.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label46
            // 
            this.label46.Location = new System.Drawing.Point(19, 92);
            this.label46.Name = "label46";
            this.label46.Size = new System.Drawing.Size(64, 23);
            this.label46.TabIndex = 26;
            this.label46.Text = "Địa chỉ :";
            this.label46.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // diachi
            // 
            this.diachi.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.diachi.BackColor = System.Drawing.SystemColors.HighlightText;
            this.diachi.Enabled = false;
            this.diachi.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.diachi.Location = new System.Drawing.Point(83, 96);
            this.diachi.Masked = MaskedTextBox.MaskedTextBox.Mask.None;
            this.diachi.Name = "diachi";
            this.diachi.Size = new System.Drawing.Size(758, 21);
            this.diachi.TabIndex = 27;
            // 
            // label11
            // 
            this.label11.Location = new System.Drawing.Point(0, 140);
            this.label11.Name = "label11";
            this.label11.Size = new System.Drawing.Size(80, 23);
            this.label11.TabIndex = 31;
            this.label11.Text = "Tài khoản có :";
            this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // ttkcoa
            // 
            this.ttkcoa.BackColor = System.Drawing.SystemColors.HighlightText;
            this.ttkcoa.Enabled = false;
            this.ttkcoa.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ttkcoa.Location = new System.Drawing.Point(153, 142);
            this.ttkcoa.Name = "ttkcoa";
            this.ttkcoa.Size = new System.Drawing.Size(232, 21);
            this.ttkcoa.TabIndex = 33;
            // 
            // tkcoa
            // 
            this.tkcoa.BackColor = System.Drawing.SystemColors.HighlightText;
            this.tkcoa.Enabled = false;
            this.tkcoa.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tkcoa.Location = new System.Drawing.Point(83, 142);
            this.tkcoa.Name = "tkcoa";
            this.tkcoa.Size = new System.Drawing.Size(69, 21);
            this.tkcoa.TabIndex = 32;
            this.tkcoa.TextChanged += new System.EventHandler(this.tkcoa_TextChanged);
            this.tkcoa.Validated += new System.EventHandler(this.tkcoa_Validated);
            this.tkcoa.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tknoa_KeyDown);
            // 
            // label12
            // 
            this.label12.Location = new System.Drawing.Point(3, 162);
            this.label12.Name = "label12";
            this.label12.Size = new System.Drawing.Size(80, 23);
            this.label12.TabIndex = 34;
            this.label12.Text = "Hợp đồng :";
            this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // hopdong
            // 
            this.hopdong.BackColor = System.Drawing.SystemColors.HighlightText;
            this.hopdong.Enabled = false;
            this.hopdong.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.hopdong.Location = new System.Drawing.Point(83, 164);
            this.hopdong.Name = "hopdong";
            this.hopdong.Size = new System.Drawing.Size(197, 21);
            this.hopdong.TabIndex = 35;
            // 
            // label33
            // 
            this.label33.Location = new System.Drawing.Point(344, 162);
            this.label33.Name = "label33";
            this.label33.Size = new System.Drawing.Size(80, 23);
            this.label33.TabIndex = 36;
            this.label33.Text = "Loại bảng kê :";
            this.label33.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // loaibk
            // 
            this.loaibk.BackColor = System.Drawing.SystemColors.HighlightText;
            this.loaibk.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.loaibk.Enabled = false;
            this.loaibk.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.loaibk.Location = new System.Drawing.Point(424, 164);
            this.loaibk.Name = "loaibk";
            this.loaibk.Size = new System.Drawing.Size(120, 21);
            this.loaibk.TabIndex = 37;
            this.loaibk.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label34
            // 
            this.label34.Location = new System.Drawing.Point(536, 162);
            this.label34.Name = "label34";
            this.label34.Size = new System.Drawing.Size(80, 23);
            this.label34.TabIndex = 38;
            this.label34.Text = "Hóa đơn :";
            this.label34.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // hoadon
            // 
            this.hoadon.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.hoadon.BackColor = System.Drawing.SystemColors.HighlightText;
            this.hoadon.Enabled = false;
            this.hoadon.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.hoadon.Location = new System.Drawing.Point(616, 164);
            this.hoadon.Name = "hoadon";
            this.hoadon.Size = new System.Drawing.Size(465, 21);
            this.hoadon.TabIndex = 39;
            // 
            // label47
            // 
            this.label47.Location = new System.Drawing.Point(3, 186);
            this.label47.Name = "label47";
            this.label47.Size = new System.Drawing.Size(80, 23);
            this.label47.TabIndex = 40;
            this.label47.Text = "Ngày :";
            this.label47.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // ngayhd
            // 
            this.ngayhd.BackColor = System.Drawing.SystemColors.HighlightText;
            this.ngayhd.Enabled = false;
            this.ngayhd.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ngayhd.Location = new System.Drawing.Point(83, 187);
            this.ngayhd.Name = "ngayhd";
            this.ngayhd.Size = new System.Drawing.Size(70, 21);
            this.ngayhd.TabIndex = 41;
            // 
            // label48
            // 
            this.label48.Location = new System.Drawing.Point(152, 186);
            this.label48.Name = "label48";
            this.label48.Size = new System.Drawing.Size(80, 23);
            this.label48.TabIndex = 42;
            this.label48.Text = "Thuế suất :";
            this.label48.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label49
            // 
            this.label49.Location = new System.Drawing.Point(344, 186);
            this.label49.Name = "label49";
            this.label49.Size = new System.Drawing.Size(80, 23);
            this.label49.TabIndex = 45;
            this.label49.Text = "Thuế GTGT :";
            this.label49.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // thuesuat
            // 
            this.thuesuat.BackColor = System.Drawing.SystemColors.HighlightText;
            this.thuesuat.Enabled = false;
            this.thuesuat.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.thuesuat.Location = new System.Drawing.Point(232, 187);
            this.thuesuat.Name = "thuesuat";
            this.thuesuat.Size = new System.Drawing.Size(48, 21);
            this.thuesuat.TabIndex = 43;
            this.thuesuat.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            // 
            // tienthue
            // 
            this.tienthue.BackColor = System.Drawing.SystemColors.HighlightText;
            this.tienthue.Enabled = false;
            this.tienthue.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tienthue.Location = new System.Drawing.Point(424, 187);
            this.tienthue.Name = "tienthue";
            this.tienthue.Size = new System.Drawing.Size(120, 21);
            this.tienthue.TabIndex = 46;
            this.tienthue.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            // 
            // label50
            // 
            this.label50.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label50.Location = new System.Drawing.Point(120, 364);
            this.label50.Name = "label50";
            this.label50.Size = new System.Drawing.Size(72, 23);
            this.label50.TabIndex = 49;
            this.label50.Text = "Loại khoản :";
            this.label50.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // lk
            // 
            this.lk.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.lk.BackColor = System.Drawing.SystemColors.HighlightText;
            this.lk.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.lk.Enabled = false;
            this.lk.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lk.Location = new System.Drawing.Point(193, 364);
            this.lk.Name = "lk";
            this.lk.Size = new System.Drawing.Size(888, 21);
            this.lk.TabIndex = 50;
            this.lk.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // ttkno
            // 
            this.ttkno.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.ttkno.BackColor = System.Drawing.SystemColors.HighlightText;
            this.ttkno.Enabled = false;
            this.ttkno.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ttkno.Location = new System.Drawing.Point(193, 388);
            this.ttkno.Name = "ttkno";
            this.ttkno.Size = new System.Drawing.Size(414, 21);
            this.ttkno.TabIndex = 53;
            // 
            // tkno
            // 
            this.tkno.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.tkno.BackColor = System.Drawing.SystemColors.HighlightText;
            this.tkno.Enabled = false;
            this.tkno.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tkno.Location = new System.Drawing.Point(83, 388);
            this.tkno.Name = "tkno";
            this.tkno.Size = new System.Drawing.Size(109, 21);
            this.tkno.TabIndex = 52;
            this.tkno.TextChanged += new System.EventHandler(this.tkno_TextChanged);
            this.tkno.Validated += new System.EventHandler(this.tkno_Validated);
            this.tkno.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tkno_KeyDown);
            // 
            // label13
            // 
            this.label13.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label13.Location = new System.Drawing.Point(3, 385);
            this.label13.Name = "label13";
            this.label13.Size = new System.Drawing.Size(80, 23);
            this.label13.TabIndex = 51;
            this.label13.Text = "Tài khoản nợ :";
            this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label16
            // 
            this.label16.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label16.Location = new System.Drawing.Point(616, 385);
            this.label16.Name = "label16";
            this.label16.Size = new System.Drawing.Size(56, 23);
            this.label16.TabIndex = 54;
            this.label16.Text = "Mục/TM :";
            this.label16.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // mtmno
            // 
            this.mtmno.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.mtmno.BackColor = System.Drawing.SystemColors.HighlightText;
            this.mtmno.Enabled = false;
            this.mtmno.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.mtmno.Location = new System.Drawing.Point(672, 387);
            this.mtmno.Name = "mtmno";
            this.mtmno.Size = new System.Drawing.Size(407, 21);
            this.mtmno.TabIndex = 55;
            this.mtmno.TextChanged += new System.EventHandler(this.mtmno_TextChanged);
            this.mtmno.Validated += new System.EventHandler(this.mtmno_Validated);
            this.mtmno.KeyDown += new System.Windows.Forms.KeyEventHandler(this.mtmno_KeyDown);
            // 
            // label17
            // 
            this.label17.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label17.Enabled = false;
            this.label17.Location = new System.Drawing.Point(839, 557);
            this.label17.Name = "label17";
            this.label17.Size = new System.Drawing.Size(0, 0);
            this.label17.TabIndex = 56;
            this.label17.Text = "K mục  :";
            this.label17.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label17.Visible = false;
            // 
            // kmno
            // 
            this.kmno.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.kmno.BackColor = System.Drawing.SystemColors.HighlightText;
            this.kmno.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.kmno.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.kmno.Location = new System.Drawing.Point(903, 387);
            this.kmno.Name = "kmno";
            this.kmno.Size = new System.Drawing.Size(0, 21);
            this.kmno.TabIndex = 57;
            this.kmno.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // ttkco
            // 
            this.ttkco.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.ttkco.BackColor = System.Drawing.SystemColors.HighlightText;
            this.ttkco.Enabled = false;
            this.ttkco.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ttkco.Location = new System.Drawing.Point(193, 410);
            this.ttkco.Name = "ttkco";
            this.ttkco.Size = new System.Drawing.Size(414, 21);
            this.ttkco.TabIndex = 66;
            // 
            // mtmco
            // 
            this.mtmco.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.mtmco.BackColor = System.Drawing.SystemColors.HighlightText;
            this.mtmco.Enabled = false;
            this.mtmco.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.mtmco.Location = new System.Drawing.Point(672, 410);
            this.mtmco.Name = "mtmco";
            this.mtmco.Size = new System.Drawing.Size(407, 21);
            this.mtmco.TabIndex = 68;
            this.mtmco.TextChanged += new System.EventHandler(this.mtmco_TextChanged);
            this.mtmco.Validated += new System.EventHandler(this.mtmco_Validated);
            this.mtmco.KeyDown += new System.Windows.Forms.KeyEventHandler(this.mtmno_KeyDown);
            // 
            // kmco
            // 
            this.kmco.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.kmco.BackColor = System.Drawing.SystemColors.HighlightText;
            this.kmco.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.kmco.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.kmco.Location = new System.Drawing.Point(903, 410);
            this.kmco.Name = "kmco";
            this.kmco.Size = new System.Drawing.Size(0, 21);
            this.kmco.TabIndex = 70;
            this.kmco.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label18
            // 
            this.label18.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label18.Enabled = false;
            this.label18.Location = new System.Drawing.Point(829, 558);
            this.label18.Name = "label18";
            this.label18.Size = new System.Drawing.Size(0, 0);
            this.label18.TabIndex = 69;
            this.label18.Text = "K mục  :";
            this.label18.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label18.Visible = false;
            // 
            // label19
            // 
            this.label19.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label19.Location = new System.Drawing.Point(616, 408);
            this.label19.Name = "label19";
            this.label19.Size = new System.Drawing.Size(56, 23);
            this.label19.TabIndex = 67;
            this.label19.Text = "Mục/TM :";
            this.label19.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // tkco
            // 
            this.tkco.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.tkco.BackColor = System.Drawing.SystemColors.HighlightText;
            this.tkco.Enabled = false;
            this.tkco.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tkco.Location = new System.Drawing.Point(83, 411);
            this.tkco.Name = "tkco";
            this.tkco.Size = new System.Drawing.Size(109, 21);
            this.tkco.TabIndex = 65;
            this.tkco.TextChanged += new System.EventHandler(this.tkco_TextChanged);
            this.tkco.Validated += new System.EventHandler(this.tkco_Validated);
            this.tkco.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tkco_KeyDown);
            // 
            // label20
            // 
            this.label20.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label20.Location = new System.Drawing.Point(3, 411);
            this.label20.Name = "label20";
            this.label20.Size = new System.Drawing.Size(80, 23);
            this.label20.TabIndex = 64;
            this.label20.Text = "Tài khoản có :";
            this.label20.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label15
            // 
            this.label15.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label15.Location = new System.Drawing.Point(19, 431);
            this.label15.Name = "label15";
            this.label15.Size = new System.Drawing.Size(64, 23);
            this.label15.TabIndex = 77;
            this.label15.Text = "Nội dung :";
            this.label15.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // mapt
            // 
            this.mapt.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.mapt.BackColor = System.Drawing.SystemColors.HighlightText;
            this.mapt.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.mapt.Enabled = false;
            this.mapt.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.mapt.Location = new System.Drawing.Point(89, 550);
            this.mapt.Name = "mapt";
            this.mapt.Size = new System.Drawing.Size(0, 21);
            this.mapt.TabIndex = 80;
            this.mapt.Visible = false;
            this.mapt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label23
            // 
            this.label23.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label23.Location = new System.Drawing.Point(9, 550);
            this.label23.Name = "label23";
            this.label23.Size = new System.Drawing.Size(0, 0);
            this.label23.TabIndex = 79;
            this.label23.Text = "Phân tích :";
            this.label23.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label23.Visible = false;
            // 
            // label24
            // 
            this.label24.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label24.Location = new System.Drawing.Point(3, 456);
            this.label24.Name = "label24";
            this.label24.Size = new System.Drawing.Size(80, 23);
            this.label24.TabIndex = 81;
            this.label24.Text = "Cấp phát :";
            this.label24.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // capphat
            // 
            this.capphat.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.capphat.BackColor = System.Drawing.SystemColors.HighlightText;
            this.capphat.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.capphat.Enabled = false;
            this.capphat.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.capphat.Location = new System.Drawing.Point(83, 457);
            this.capphat.Name = "capphat";
            this.capphat.Size = new System.Drawing.Size(112, 21);
            this.capphat.TabIndex = 82;
            this.capphat.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // ngoaite
            // 
            this.ngoaite.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.ngoaite.BackColor = System.Drawing.SystemColors.HighlightText;
            this.ngoaite.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.ngoaite.Enabled = false;
            this.ngoaite.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ngoaite.Location = new System.Drawing.Point(248, 457);
            this.ngoaite.Name = "ngoaite";
            this.ngoaite.Size = new System.Drawing.Size(56, 21);
            this.ngoaite.TabIndex = 84;
            this.ngoaite.SelectedIndexChanged += new System.EventHandler(this.ngoaite_SelectedIndexChanged);
            this.ngoaite.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label25
            // 
            this.label25.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label25.Location = new System.Drawing.Point(168, 456);
            this.label25.Name = "label25";
            this.label25.Size = new System.Drawing.Size(80, 23);
            this.label25.TabIndex = 83;
            this.label25.Text = "Ngoại tệ :";
            this.label25.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // tonghop
            // 
            this.tonghop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.tonghop.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.tonghop.Enabled = false;
            this.tonghop.Location = new System.Drawing.Point(24, 484);
            this.tonghop.Name = "tonghop";
            this.tonghop.Size = new System.Drawing.Size(72, 16);
            this.tonghop.TabIndex = 91;
            this.tonghop.Text = "Tổng hợp";
            this.tonghop.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // butBangke
            // 
            this.butBangke.Enabled = false;
            this.butBangke.Image = ((System.Drawing.Image)(resources.GetObject("butBangke.Image")));
            this.butBangke.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butBangke.Location = new System.Drawing.Point(569, 562);
            this.butBangke.Name = "butBangke";
            this.butBangke.Size = new System.Drawing.Size(0, 0);
            this.butBangke.TabIndex = 100;
            this.butBangke.Text = "&Chi tiết bảng kê";
            this.butBangke.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label26
            // 
            this.label26.Location = new System.Drawing.Point(-8, 72);
            this.label26.Name = "label26";
            this.label26.Size = new System.Drawing.Size(88, 23);
            this.label26.TabIndex = 21;
            this.label26.Text = "Loại đối tượng :";
            this.label26.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // loaidt
            // 
            this.loaidt.BackColor = System.Drawing.SystemColors.HighlightText;
            this.loaidt.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.loaidt.Enabled = false;
            this.loaidt.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.loaidt.Location = new System.Drawing.Point(83, 73);
            this.loaidt.Name = "loaidt";
            this.loaidt.Size = new System.Drawing.Size(93, 21);
            this.loaidt.TabIndex = 22;
            this.loaidt.SelectedIndexChanged += new System.EventHandler(this.loaidt_SelectedIndexChanged);
            this.loaidt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // tendt
            // 
            this.tendt.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.tendt.BackColor = System.Drawing.SystemColors.HighlightText;
            this.tendt.Enabled = false;
            this.tendt.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tendt.Location = new System.Drawing.Point(347, 73);
            this.tendt.Name = "tendt";
            this.tendt.Size = new System.Drawing.Size(734, 21);
            this.tendt.TabIndex = 25;
            this.tendt.TextChanged += new System.EventHandler(this.tendt_TextChanged);
            this.tendt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tendt_KeyDown);
            // 
            // madt
            // 
            this.madt.BackColor = System.Drawing.SystemColors.HighlightText;
            this.madt.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.madt.Enabled = false;
            this.madt.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.madt.Location = new System.Drawing.Point(232, 73);
            this.madt.Name = "madt";
            this.madt.Size = new System.Drawing.Size(112, 21);
            this.madt.TabIndex = 24;
            this.madt.Validated += new System.EventHandler(this.madt_Validated);
            this.madt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label27
            // 
            this.label27.Location = new System.Drawing.Point(152, 72);
            this.label27.Name = "label27";
            this.label27.Size = new System.Drawing.Size(80, 23);
            this.label27.TabIndex = 23;
            this.label27.Text = "Tên :";
            this.label27.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // listmtm
            // 
            this.listmtm.BackColor = System.Drawing.SystemColors.Info;
            this.listmtm.ColumnCount = 0;
            this.listmtm.Location = new System.Drawing.Point(670, 554);
            this.listmtm.MatchBufferTimeOut = 1000;
            this.listmtm.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
            this.listmtm.Name = "listmtm";
            this.listmtm.Size = new System.Drawing.Size(0, 4);
            this.listmtm.TabIndex = 101;
            this.listmtm.TextIndex = -1;
            this.listmtm.TextMember = null;
            this.listmtm.ValueIndex = -1;
            this.listmtm.Visible = false;
            this.listmtm.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listmtm_KeyDown);
            // 
            // liststk
            // 
            this.liststk.BackColor = System.Drawing.SystemColors.Info;
            this.liststk.ColumnCount = 0;
            this.liststk.Location = new System.Drawing.Point(462, 562);
            this.liststk.MatchBufferTimeOut = 1000;
            this.liststk.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
            this.liststk.Name = "liststk";
            this.liststk.Size = new System.Drawing.Size(0, 4);
            this.liststk.TabIndex = 102;
            this.liststk.TextIndex = -1;
            this.liststk.TextMember = null;
            this.liststk.ValueIndex = -1;
            this.liststk.Visible = false;
            this.liststk.KeyDown += new System.Windows.Forms.KeyEventHandler(this.liststk_KeyDown);
            // 
            // stemp
            // 
            this.stemp.Enabled = false;
            this.stemp.Location = new System.Drawing.Point(576, 240);
            this.stemp.Name = "stemp";
            this.stemp.Size = new System.Drawing.Size(100, 20);
            this.stemp.TabIndex = 103;
            // 
            // listtkno
            // 
            this.listtkno.BackColor = System.Drawing.SystemColors.Info;
            this.listtkno.ColumnCount = 0;
            this.listtkno.Location = new System.Drawing.Point(238, 562);
            this.listtkno.MatchBufferTimeOut = 1000;
            this.listtkno.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
            this.listtkno.Name = "listtkno";
            this.listtkno.Size = new System.Drawing.Size(0, 4);
            this.listtkno.TabIndex = 104;
            this.listtkno.TextIndex = -1;
            this.listtkno.TextMember = null;
            this.listtkno.ValueIndex = -1;
            this.listtkno.Visible = false;
            this.listtkno.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listtkno_KeyDown);
            // 
            // listtkco
            // 
            this.listtkco.BackColor = System.Drawing.SystemColors.Info;
            this.listtkco.ColumnCount = 0;
            this.listtkco.Location = new System.Drawing.Point(318, 562);
            this.listtkco.MatchBufferTimeOut = 1000;
            this.listtkco.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
            this.listtkco.Name = "listtkco";
            this.listtkco.Size = new System.Drawing.Size(0, 4);
            this.listtkco.TabIndex = 105;
            this.listtkco.TextIndex = -1;
            this.listtkco.TextMember = null;
            this.listtkco.ValueIndex = -1;
            this.listtkco.Visible = false;
            this.listtkco.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listtkco_KeyDown);
            // 
            // noidung
            // 
            this.noidung.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.noidung.BackColor = System.Drawing.SystemColors.HighlightText;
            this.noidung.Enabled = false;
            this.noidung.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.noidung.Location = new System.Drawing.Point(83, 433);
            this.noidung.Name = "noidung";
            this.noidung.Size = new System.Drawing.Size(996, 21);
            this.noidung.TabIndex = 78;
            this.noidung.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label28
            // 
            this.label28.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.label28.Location = new System.Drawing.Point(825, 96);
            this.label28.Name = "label28";
            this.label28.Size = new System.Drawing.Size(88, 23);
            this.label28.TabIndex = 106;
            this.label28.Text = "Số tài khoản :";
            this.label28.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // sotk
            // 
            this.sotk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.sotk.BackColor = System.Drawing.SystemColors.HighlightText;
            this.sotk.Enabled = false;
            this.sotk.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.sotk.Location = new System.Drawing.Point(913, 96);
            this.sotk.Masked = MaskedTextBox.MaskedTextBox.Mask.None;
            this.sotk.MaxLength = 50;
            this.sotk.Name = "sotk";
            this.sotk.Size = new System.Drawing.Size(168, 21);
            this.sotk.TabIndex = 107;
            // 
            // sotkno
            // 
            this.sotkno.BackColor = System.Drawing.SystemColors.HighlightText;
            this.sotkno.Enabled = false;
            this.sotkno.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.sotkno.Location = new System.Drawing.Point(424, 119);
            this.sotkno.Masked = MaskedTextBox.MaskedTextBox.Mask.None;
            this.sotkno.MaxLength = 50;
            this.sotkno.Name = "sotkno";
            this.sotkno.Size = new System.Drawing.Size(120, 21);
            this.sotkno.TabIndex = 109;
            // 
            // label29
            // 
            this.label29.Location = new System.Drawing.Point(336, 120);
            this.label29.Name = "label29";
            this.label29.Size = new System.Drawing.Size(88, 23);
            this.label29.TabIndex = 108;
            this.label29.Text = "Số TK :";
            this.label29.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // tennhno
            // 
            this.tennhno.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.tennhno.BackColor = System.Drawing.SystemColors.HighlightText;
            this.tennhno.Enabled = false;
            this.tennhno.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tennhno.Location = new System.Drawing.Point(616, 119);
            this.tennhno.Masked = MaskedTextBox.MaskedTextBox.Mask.None;
            this.tennhno.MaxLength = 50;
            this.tennhno.Name = "tennhno";
            this.tennhno.Size = new System.Drawing.Size(465, 21);
            this.tennhno.TabIndex = 111;
            // 
            // label30
            // 
            this.label30.Location = new System.Drawing.Point(528, 120);
            this.label30.Name = "label30";
            this.label30.Size = new System.Drawing.Size(88, 23);
            this.label30.TabIndex = 110;
            this.label30.Text = "Ngân hàng :";
            this.label30.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // sotkco
            // 
            this.sotkco.BackColor = System.Drawing.SystemColors.HighlightText;
            this.sotkco.Enabled = false;
            this.sotkco.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.sotkco.Location = new System.Drawing.Point(424, 142);
            this.sotkco.Masked = MaskedTextBox.MaskedTextBox.Mask.None;
            this.sotkco.MaxLength = 50;
            this.sotkco.Name = "sotkco";
            this.sotkco.Size = new System.Drawing.Size(120, 21);
            this.sotkco.TabIndex = 113;
            // 
            // tennhco
            // 
            this.tennhco.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.tennhco.BackColor = System.Drawing.SystemColors.HighlightText;
            this.tennhco.Enabled = false;
            this.tennhco.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tennhco.Location = new System.Drawing.Point(616, 142);
            this.tennhco.Masked = MaskedTextBox.MaskedTextBox.Mask.None;
            this.tennhco.MaxLength = 50;
            this.tennhco.Name = "tennhco";
            this.tennhco.Size = new System.Drawing.Size(465, 21);
            this.tennhco.TabIndex = 115;
            // 
            // label31
            // 
            this.label31.Location = new System.Drawing.Point(528, 140);
            this.label31.Name = "label31";
            this.label31.Size = new System.Drawing.Size(88, 23);
            this.label31.TabIndex = 114;
            this.label31.Text = "Ngân hàng :";
            this.label31.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label32
            // 
            this.label32.Location = new System.Drawing.Point(336, 140);
            this.label32.Name = "label32";
            this.label32.Size = new System.Drawing.Size(88, 23);
            this.label32.TabIndex = 112;
            this.label32.Text = "Số TK :";
            this.label32.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // noidunga
            // 
            this.noidunga.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.noidunga.BackColor = System.Drawing.SystemColors.HighlightText;
            this.noidunga.Enabled = false;
            this.noidunga.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.noidunga.Location = new System.Drawing.Point(232, 50);
            this.noidunga.Name = "noidunga";
            this.noidunga.Size = new System.Drawing.Size(849, 21);
            this.noidunga.TabIndex = 20;
            this.noidunga.Validated += new System.EventHandler(this.noidunga_Validated);
            this.noidunga.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // chkXml
            // 
            this.chkXml.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.chkXml.Location = new System.Drawing.Point(983, 500);
            this.chkXml.Name = "chkXml";
            this.chkXml.Size = new System.Drawing.Size(88, 16);
            this.chkXml.TabIndex = 116;
            this.chkXml.Text = "Xuất ra XML";
            // 
            // nhom
            // 
            this.nhom.BackColor = System.Drawing.SystemColors.HighlightText;
            this.nhom.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.nhom.Enabled = false;
            this.nhom.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.nhom.Location = new System.Drawing.Point(83, 4);
            this.nhom.Name = "nhom";
            this.nhom.Size = new System.Drawing.Size(85, 21);
            this.nhom.TabIndex = 0;
            this.nhom.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label36
            // 
            this.label36.Location = new System.Drawing.Point(24, 4);
            this.label36.Name = "label36";
            this.label36.Size = new System.Drawing.Size(56, 23);
            this.label36.TabIndex = 131;
            this.label36.Text = "Nhóm :";
            this.label36.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // kmno3
            // 
            this.kmno3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.kmno3.BackColor = System.Drawing.SystemColors.HighlightText;
            this.kmno3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.kmno3.Enabled = false;
            this.kmno3.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.kmno3.Location = new System.Drawing.Point(826, 557);
            this.kmno3.Name = "kmno3";
            this.kmno3.Size = new System.Drawing.Size(0, 21);
            this.kmno3.TabIndex = 61;
            this.kmno3.Visible = false;
            this.kmno3.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // kmno2
            // 
            this.kmno2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.kmno2.BackColor = System.Drawing.SystemColors.HighlightText;
            this.kmno2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.kmno2.Enabled = false;
            this.kmno2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.kmno2.Location = new System.Drawing.Point(842, 554);
            this.kmno2.Name = "kmno2";
            this.kmno2.Size = new System.Drawing.Size(0, 21);
            this.kmno2.TabIndex = 59;
            this.kmno2.Visible = false;
            this.kmno2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // kmno4
            // 
            this.kmno4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.kmno4.BackColor = System.Drawing.SystemColors.HighlightText;
            this.kmno4.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.kmno4.Enabled = false;
            this.kmno4.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.kmno4.Location = new System.Drawing.Point(790, 554);
            this.kmno4.Name = "kmno4";
            this.kmno4.Size = new System.Drawing.Size(0, 21);
            this.kmno4.TabIndex = 63;
            this.kmno4.Visible = false;
            this.kmno4.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label39
            // 
            this.label39.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label39.Enabled = false;
            this.label39.Location = new System.Drawing.Point(786, 552);
            this.label39.Name = "label39";
            this.label39.Size = new System.Drawing.Size(0, 0);
            this.label39.TabIndex = 62;
            this.label39.Text = "K mục 4 :";
            this.label39.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label39.Visible = false;
            // 
            // label40
            // 
            this.label40.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label40.Enabled = false;
            this.label40.Location = new System.Drawing.Point(787, 554);
            this.label40.Name = "label40";
            this.label40.Size = new System.Drawing.Size(0, 0);
            this.label40.TabIndex = 60;
            this.label40.Text = "K mục 3 :";
            this.label40.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label40.Visible = false;
            // 
            // label41
            // 
            this.label41.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label41.Enabled = false;
            this.label41.Location = new System.Drawing.Point(790, 558);
            this.label41.Name = "label41";
            this.label41.Size = new System.Drawing.Size(0, 0);
            this.label41.TabIndex = 58;
            this.label41.Text = "Khoản mục 2 :";
            this.label41.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label41.Visible = false;
            // 
            // kmco3
            // 
            this.kmco3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.kmco3.BackColor = System.Drawing.SystemColors.HighlightText;
            this.kmco3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.kmco3.Enabled = false;
            this.kmco3.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.kmco3.Location = new System.Drawing.Point(903, 527);
            this.kmco3.Name = "kmco3";
            this.kmco3.Size = new System.Drawing.Size(0, 21);
            this.kmco3.TabIndex = 74;
            this.kmco3.Visible = false;
            this.kmco3.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // kmco2
            // 
            this.kmco2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.kmco2.BackColor = System.Drawing.SystemColors.HighlightText;
            this.kmco2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.kmco2.Enabled = false;
            this.kmco2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.kmco2.Location = new System.Drawing.Point(893, 550);
            this.kmco2.Name = "kmco2";
            this.kmco2.Size = new System.Drawing.Size(0, 21);
            this.kmco2.TabIndex = 72;
            this.kmco2.Visible = false;
            this.kmco2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // kmco4
            // 
            this.kmco4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.kmco4.BackColor = System.Drawing.SystemColors.HighlightText;
            this.kmco4.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.kmco4.Enabled = false;
            this.kmco4.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.kmco4.Location = new System.Drawing.Point(594, 550);
            this.kmco4.Name = "kmco4";
            this.kmco4.Size = new System.Drawing.Size(0, 21);
            this.kmco4.TabIndex = 76;
            this.kmco4.Visible = false;
            this.kmco4.KeyDown += new System.Windows.Forms.KeyEventHandler(this.hoatdong_KeyDown);
            // 
            // label42
            // 
            this.label42.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label42.Enabled = false;
            this.label42.Location = new System.Drawing.Point(842, 557);
            this.label42.Name = "label42";
            this.label42.Size = new System.Drawing.Size(0, 0);
            this.label42.TabIndex = 75;
            this.label42.Text = "K mục 4 :";
            this.label42.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label42.Visible = false;
            // 
            // label44
            // 
            this.label44.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label44.Enabled = false;
            this.label44.Location = new System.Drawing.Point(833, 558);
            this.label44.Name = "label44";
            this.label44.Size = new System.Drawing.Size(0, 0);
            this.label44.TabIndex = 73;
            this.label44.Text = "K mục 3 :";
            this.label44.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label44.Visible = false;
            // 
            // label51
            // 
            this.label51.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label51.Enabled = false;
            this.label51.Location = new System.Drawing.Point(803, 552);
            this.label51.Name = "label51";
            this.label51.Size = new System.Drawing.Size(0, 0);
            this.label51.TabIndex = 71;
            this.label51.Text = "Khoản mục 2 :";
            this.label51.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.label51.Visible = false;
            // 
            // label52
            // 
            this.label52.Location = new System.Drawing.Point(750, 26);
            this.label52.Name = "label52";
            this.label52.Size = new System.Drawing.Size(83, 23);
            this.label52.TabIndex = 192;
            this.label52.Text = "Mã nguồn NS:";
            this.label52.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // cbnguonns
            // 
            this.cbnguonns.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.cbnguonns.BackColor = System.Drawing.SystemColors.HighlightText;
            this.cbnguonns.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.cbnguonns.Enabled = false;
            this.cbnguonns.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cbnguonns.Location = new System.Drawing.Point(826, 26);
            this.cbnguonns.Name = "cbnguonns";
            this.cbnguonns.Size = new System.Drawing.Size(255, 21);
            this.cbnguonns.TabIndex = 193;
            // 
            // label53
            // 
            this.label53.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label53.Location = new System.Drawing.Point(840, 386);
            this.label53.Name = "label53";
            this.label53.Size = new System.Drawing.Size(0, 0);
            this.label53.TabIndex = 194;
            this.label53.Text = "Nguồn :";
            this.label53.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label54
            // 
            this.label54.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label54.Location = new System.Drawing.Point(840, 407);
            this.label54.Name = "label54";
            this.label54.Size = new System.Drawing.Size(0, 0);
            this.label54.TabIndex = 195;
            this.label54.Text = "Nguồn :";
            this.label54.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // frmNhapng
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(1089, 569);
            this.Controls.Add(this.label54);
            this.Controls.Add(this.label53);
            this.Controls.Add(this.cbnguonns);
            this.Controls.Add(this.label52);
            this.Controls.Add(this.butHD);
            this.Controls.Add(this.tygia);
            this.Controls.Add(this.kmco3);
            this.Controls.Add(this.kmco2);
            this.Controls.Add(this.kmco4);
            this.Controls.Add(this.label42);
            this.Controls.Add(this.label44);
            this.Controls.Add(this.label51);
            this.Controls.Add(this.kmno3);
            this.Controls.Add(this.kmno2);
            this.Controls.Add(this.kmno4);
            this.Controls.Add(this.label39);
            this.Controls.Add(this.label40);
            this.Controls.Add(this.label41);
            this.Controls.Add(this.ctgs);
            this.Controls.Add(this.nhom);
            this.Controls.Add(this.label36);
            this.Controls.Add(this.chkXml);
            this.Controls.Add(this.noidunga);
            this.Controls.Add(this.ttkcoa);
            this.Controls.Add(this.sotkco);
            this.Controls.Add(this.tennhco);
            this.Controls.Add(this.label31);
            this.Controls.Add(this.label32);
            this.Controls.Add(this.sotkno);
            this.Controls.Add(this.tennhno);
            this.Controls.Add(this.label30);
            this.Controls.Add(this.ttknoa);
            this.Controls.Add(this.label29);
            this.Controls.Add(this.sotk);
            this.Controls.Add(this.diachi);
            this.Controls.Add(this.label28);
            this.Controls.Add(this.znguyente);
            this.Controls.Add(this.zstien);
            this.Controls.Add(this.noidung);
            this.Controls.Add(this.listtkco);
            this.Controls.Add(this.listtkno);
            this.Controls.Add(this.liststk);
            this.Controls.Add(this.listmtm);
            this.Controls.Add(this.loaidt);
            this.Controls.Add(this.tendt);
            this.Controls.Add(this.madt);
            this.Controls.Add(this.label27);
            this.Controls.Add(this.label26);
            this.Controls.Add(this.butBangke);
            this.Controls.Add(this.tt);
            this.Controls.Add(this.tonghop);
            this.Controls.Add(this.capphat);
            this.Controls.Add(this.ngoaite);
            this.Controls.Add(this.label25);
            this.Controls.Add(this.mapt);
            this.Controls.Add(this.label24);
            this.Controls.Add(this.label23);
            this.Controls.Add(this.label15);
            this.Controls.Add(this.ttkco);
            this.Controls.Add(this.mtmco);
            this.Controls.Add(this.kmco);
            this.Controls.Add(this.label18);
            this.Controls.Add(this.label19);
            this.Controls.Add(this.tkco);
            this.Controls.Add(this.label20);
            this.Controls.Add(this.ttkno);
            this.Controls.Add(this.mtmno);
            this.Controls.Add(this.kmno);
            this.Controls.Add(this.label17);
            this.Controls.Add(this.label16);
            this.Controls.Add(this.tkno);
            this.Controls.Add(this.label13);
            this.Controls.Add(this.lk);
            this.Controls.Add(this.label50);
            this.Controls.Add(this.tienthue);
            this.Controls.Add(this.thuesuat);
            this.Controls.Add(this.label49);
            this.Controls.Add(this.label48);
            this.Controls.Add(this.loaibk);
            this.Controls.Add(this.hoadon);
            this.Controls.Add(this.ngayhd);
            this.Controls.Add(this.label47);
            this.Controls.Add(this.label34);
            this.Controls.Add(this.label33);
            this.Controls.Add(this.hopdong);
            this.Controls.Add(this.label12);
            this.Controls.Add(this.tkcoa);
            this.Controls.Add(this.label11);
            this.Controls.Add(this.label46);
            this.Controls.Add(this.tcnkp);
            this.Controls.Add(this.label45);
            this.Controls.Add(this.nghiepvu);
            this.Controls.Add(this.chuong);
            this.Controls.Add(this.label7);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.nguyente);
            this.Controls.Add(this.label43);
            this.Controls.Add(this.stien);
            this.Controls.Add(this.label37);
            this.Controls.Add(this.label38);
            this.Controls.Add(this.label21);
            this.Controls.Add(this.label35);
            this.Controls.Add(this.lsokhoan);
            this.Controls.Add(this.chkIn);
            this.Controls.Add(this.find);
            this.Controls.Add(this.cmbSoctg);
            this.Controls.Add(this.soctg);
            this.Controls.Add(this.label22);
            this.Controls.Add(this.butKetthuc);
            this.Controls.Add(this.butIn);
            this.Controls.Add(this.butHuy);
            this.Controls.Add(this.butBoqua);
            this.Controls.Add(this.butXoa);
            this.Controls.Add(this.butThem);
            this.Controls.Add(this.butLuu);
            this.Controls.Add(this.butSua);
            this.Controls.Add(this.butMoi);
            this.Controls.Add(this.label14);
            this.Controls.Add(this.lctug);
            this.Controls.Add(this.hoatdong);
            this.Controls.Add(this.label10);
            this.Controls.Add(this.label9);
            this.Controls.Add(this.dataGrid1);
            this.Controls.Add(this.listdt);
            this.Controls.Add(this.tknoa);
            this.Controls.Add(this.ngaygs);
            this.Controls.Add(this.ngayg);
            this.Controls.Add(this.label8);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.stt);
            this.Controls.Add(this.stemp);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.KeyPreview = true;
            this.Name = "frmNhapng";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Phiếu nhập chứng từ";
            this.Load += new System.EventHandler(this.frmNhapng_Load);
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.frmNhapng_KeyDown);
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.tt)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		private void frmNhapng_Load(object sender, System.EventArgs e)
		{			
			user=a.user;
			chkIn.Checked=a.bPreview;
			bSophieu=a.bSophieu_tudong;
			bSophieu_nam=a.bSophieu_nam;
			format_sotien=a.format_sotien(0);
			bKhoaso=a.bKhoaso(s_mmyy);
			i_songay=a.Ngaylv_Ngayht;
			s_stkdt="";
			dtht=a.get_data("select * from a_hachtoan"+s_mmyy.Substring(2)+" where loai=3").Tables[0];
			foreach(DataRow r1 in dtht.Rows) s_stkdt+=r1["stk"].ToString().Trim()+",";

			nhom.DisplayMember="TEN";
			nhom.ValueMember="ID";
			nhom.DataSource=a.get_data("select * from a_dmnhombc order by stt").Tables[0];

			hoatdong.DisplayMember="TEN";
			hoatdong.ValueMember="ID";
			hoatdong.DataSource=a.get_data("select * from a_hoatdong where sudung=1 order by stt").Tables[0];

			dtloai=a.get_data("select * from a_bcnghang where chucnang="+chucnang+" and dutoanns=0 order by stt").Tables[0];
			lctug.DisplayMember="TEN";
			lctug.ValueMember="ID";
			lctug.DataSource=dtloai;

			sql="select * from a_dmchuong where sudung=1";
			if (s_chuong!="") sql+=" and id in ("+s_chuong.Substring(0,s_chuong.Length-1)+")";
			sql+=" order by stt";
			chuong.DisplayMember="TEN";
			chuong.ValueMember="ID";
			chuong.DataSource=a.get_data(sql).Tables[0];

			tcnkp.DisplayMember="TEN";
			tcnkp.ValueMember="ID";
			tcnkp.DataSource=a.get_data("select * from a_dmtcnkp where sudung=1 order by stt").Tables[0];

			sql="select * from a_nghiepvu where sudung=1";
			if (s_nghiepvu!="") sql+=" and id in ("+s_nghiepvu.Substring(0,s_nghiepvu.Length-1)+")";
			sql+=" order by id";
			nghiepvu.DisplayMember="TEN";
			nghiepvu.ValueMember="ID";
			nghiepvu.DataSource=a.get_data(sql).Tables[0];

			dtnh=a.get_data("select * from a_dmnh").Tables[0];


			dtloaidt=a.get_data("select id,ten from a_dmloaidt where sudung=-1 order by stt").Tables[0];
			r=dtloaidt.NewRow();
			r["id"]=-2;
			r["ten"]="Tất cả";
			dtloaidt.Rows.Add(r);
			foreach(DataRow r1 in a.get_data("select id,ten from a_dmloaidt where sudung=1 order by stt").Tables[0].Rows)
			{
				r=dtloaidt.NewRow();
				r["id"]=r1["id"].ToString();
				r["ten"]=r1["ten"].ToString();
				dtloaidt.Rows.Add(r);
			}
			loaidt.DisplayMember="TEN";
			loaidt.ValueMember="ID";
			loaidt.DataSource=dtloaidt;
			loaidt.SelectedIndex=0;
			
			loaibk.DisplayMember="TEN";
			loaibk.ValueMember="ID";
			loaibk.DataSource=a.get_data("select * from a_dmloaibk where sudung=1 order by stt").Tables[0];
            
			lk.DisplayMember="LK";
			lk.ValueMember="ID";
			lk.DataSource=a.get_data("select id,lk||' '||tlk as lk,tlk from a_dmlk order by stt").Tables[0];

			capphat.DisplayMember="TEN";
			capphat.ValueMember="ID";
			capphat.DataSource=a.get_data("select * from a_dmcapphat where sudung=1 order by stt").Tables[0];
			
			mapt.DisplayMember="TEN";
			mapt.ValueMember="ID";
			            
			kmno.DisplayMember="TEN";
			kmno.ValueMember="ID";

			kmno2.DisplayMember="TEN";
			kmno2.ValueMember="ID";

			kmno3.DisplayMember="TEN";
			kmno3.ValueMember="ID";

			kmno4.DisplayMember="TEN";
			kmno4.ValueMember="ID";

			kmco.DisplayMember="TEN";
			kmco.ValueMember="ID";

			kmco2.DisplayMember="TEN";
			kmco2.ValueMember="ID";

			kmco3.DisplayMember="TEN";
			kmco3.ValueMember="ID";

			kmco4.DisplayMember="TEN";
			kmco4.ValueMember="ID";

			dttk=a.get_data("select stk,ttk,congno,tinhchat,mlns,ctmlns,loaikm,loaikm2,loaikm3,loaikm4,id from a_dmtk where sudung=1 and c=1 order by stk").Tables[0];
			dtmtm=a.get_data("select * from a_dmch where sudung=1 order by stk").Tables[0];

			liststk.DisplayMember="STK";
			liststk.ValueMember="TTK";
			liststk.DataSource=dttk;

			listtkno.DisplayMember="STK";
			listtkno.ValueMember="TTK";
			listtkno.DataSource=dttk;

			listtkco.DisplayMember="STK";
			listtkco.ValueMember="TTK";
			listtkco.DataSource=dttk;

			listmtm.DisplayMember="STK";
			listmtm.ValueMember="TTK";

			dtdt=a.get_data("select mavt,tendt,diachi,loaidt,sotaikhoan,id from a_dmdt where sudung=1 order by stt").Tables[0];
			listdt.DisplayMember="MAVT";
			listdt.ValueMember="TENDT";
			listdt.DataSource=dtdt;

			sql= "select id,ma,ten,to_char(ngay,'dd/mm/yyyy') as ngay,tygia from a_dmngoaite where sudung=1 order by id";
			dtnt=a.get_data(sql).Tables[0];
			ngoaite.DisplayMember="MA";
			ngoaite.ValueMember="ID";
			ngoaite.DataSource=dtnt;

			// them combo nguon ngan sach 
			sql = "select * from a_dmngns where sudung=1 order by id";
			dtnns=a.get_data(sql).Tables[0];
			cbnguonns.DisplayMember="MANS";
			cbnguonns.ValueMember="ID";
			cbnguonns.DataSource=dtnns;

			
			//ket thuc combo nguon ngan sach

          
			sql="select a.id,a.idbc,a.mact,a.chuong,a.chucnang,a.hoatdong,a.lctug,a.soctg,to_char(a.ngayg,'dd/mm/yyyy') as ngayg,";
			sql+="to_char(a.ngaygs,'dd/mm/yyyy') as ngaygs,a.noidung,a.tknoa,a.tkcoa,";
			sql+="a.loaidt,a.madt,a.stien,a.nguyente,a.thanggs,";
			sql+="a.nghiepvu,a.loaibk,a.tcnkp,a.lanin,a.hopdong,a.ctgs,a.userid,";
			sql+="e.stk as stknoa,f.stk as stkcoa,e.ttk as ttknoa,f.ttk as ttkcoa,";
			sql+="h.mavt,h.tendt,h.diachi,m.sohd,o.loaihd,o.kyhieu,o.sohd as sobk,";
			sql+="to_char(o.ngayhd,'dd/mm/yyyy') as ngaybk,o.thuexuat,o.tienthue,p.tendt as tendtk,";
			sql+="p.diachi as diachik,q.ten as tenhoatdong,h.sotaikhoan,";
			sql+="nvl(s.account,'') as accountno,";
			sql+="nvl(t.account,'') as accountco,";
			sql+="nvl(s.tennh,'') as tennhno,";
			sql+="nvl(t.tennh,'') as tennhco,";
			sql+="h.masothue,a.iddongthoi,ns.mans,ns.tenns,a.manns as idns";
			sql+=" from a_ct"+s_mmyy.Substring(2)+" a inner join a_dmchuong b on a.chuong=b.id ";
			sql+=" inner join a_dmchucnang c on a.chucnang=c.id ";
			sql+=" inner join a_bcnghang d on a.lctug=d.id ";
			sql+=" left join a_dmtk e on a.tknoa=e.id ";
			sql+=" left join a_dmtk f on a.tkcoa=f.id ";
			sql+=" left join a_dmloaidt g on a.loaidt=g.id ";
			sql+=" left join a_dmdt h on a.madt=h.id ";
			sql+=" inner join a_nghiepvu i on a.nghiepvu=i.id ";
			sql+=" left join a_dmloaibk j on a.loaibk=j.id ";
			sql+=" left join a_dmtcnkp k on a.tcnkp=k.id ";
			sql+=" left join a_theodoihd m on a.hopdong=m.id ";
			sql+=" left join a_ctbk"+s_mmyy.Substring(2)+" o on a.id=o.id ";
			sql+=" left join a_ctk"+s_mmyy.Substring(2)+" p on a.id=p.id ";
			sql+=" inner join a_hoatdong q on a.hoatdong=q.id ";
			sql+=" left join a_dmnh s on a.tknoa=s.stk ";
			sql+=" left join a_dmnh t on a.tkcoa=t.stk ";
			sql+=" left join a_dmngns ns on a.manns=ns.id ";
			sql+=" where thanggs='"+s_mmyy.Substring(0,2)+"' and a.chucnang="+chucnang;
			if (s_chuong!="") sql+=" and a.chuong in ("+s_chuong.Substring(0,s_chuong.Length-1)+")";
			if (s_nghiepvu!="") sql+=" and a.nghiepvu in ("+s_nghiepvu.Substring(0,s_nghiepvu.Length-1)+")";
			if (s_lctug!="") sql+=" and a.lctug in ("+s_lctug.Substring(0,s_lctug.Length-1)+")";
			if (!bAdmin) sql+=" and a.userid="+i_userid;
			sql+=" and a.id<>a.iddongthoi";
			sql+=" order by d.stt,a.soctg";
			dtll=a.get_data(sql).Tables[0];
			cmbSoctg.DisplayMember="SOCTG";
			cmbSoctg.ValueMember="ID";
			cmbSoctg.DataSource=dtll;
			l_id=l_idtim;
			if (l_id==0)
			{
				if (dtll.Rows.Count>0) l_id=long.Parse(cmbSoctg.SelectedValue.ToString());
				else l_id=0;
			}
			else cmbSoctg.SelectedValue=l_id.ToString();
			load_head();
			AddGridTableStyle();
			dsxoa.ReadXml("..\\..\\..\\xml\\a_ctct.xml");
			cbnguonns.SelectedIndex=-1; 
			cbnguonns.Text="";
		}

		private void load_grid()
		{
			dataGrid1.DataSource=null;
			sql="select a.id,a.idct,a.stt,a.lk,a.noidung,a.tknoa,a.tkcoa,a.kmno,a.kmno2,a.kmno3,a.kmno4,a.kmco,a.kmco2,a.kmco3,a.kmco4,a.mtmno,a.mtmco,";
			sql+="a.stien,a.nguyente,a.ngoaite,a.tygia,n.ma as mangoaite,a.tonghop,a.mapt,a.ctgs,b.lk as tenlk,";
			sql+="c.stk as stknoa,d.stk as stkcoa,";
			sql+="nvl(e.stk,' ') as stkmtmno,nvl(f.stk,' ') as stkmtmco,nvl(g.ten,' ') as tenpt,";
			sql+="nvl(h.ten,' ') as tenkmno,nvl(i.ten,' ') as tenkmco,";
			sql+="c.mlns as mlnsno,c.ctmlns as ctmlnsno,d.mlns as mlnsco,d.ctmlns as ctmlnsco,";
			sql+="c.loaikm as loaikmno,d.loaikm as loaikmco,a.capphat,j.ten as tencapphat,a.thangqt";
			sql+=" from a_ctct"+s_mmyy.Substring(2)+" a inner join a_dmlk b on a.lk=b.id ";
			sql+=" left join a_dmtk c on a.tknoa=c.id ";
			sql+=" left join a_dmtk d on a.tkcoa=d.id ";
			sql+=" left join a_dmch e on a.mtmno=e.id ";
			sql+=" left join a_dmch f on a.mtmco=f.id ";
			sql+=" left join a_phantich g on a.mapt=g.id ";
			sql+=" left join a_dmkhoanmuc h on a.kmno=h.id ";
			sql+=" left join a_dmkhoanmuc i on a.kmco=i.id ";
			sql+=" left join a_dmcapphat j on a.capphat=j.id ";
			sql+=" left join a_dmngoaite n on a.ngoaite=n.id ";			
			sql+=" where a.idct="+l_id;
			sql+=" order by a.stt";
			dtct=a.get_data(sql).Tables[0];
			dataGrid1.DataSource=dtct;
			tongcong();
			lsokhoan.Text="TỔNG SỐ KHOẢN :"+dtct.Rows.Count.ToString();
		}

		private void ref_text()
		{
			try
			{
				int i=dataGrid1.CurrentCell.RowNumber;
				l_idct=long.Parse(dataGrid1[i,0].ToString());
				r=a.getrowbyid(dtct,"id="+l_idct);
				if (r!=null)
				{
					tt.Value=decimal.Parse(r["stt"].ToString());
					lk.SelectedValue=int.Parse(r["lk"].ToString());
					ltkno=long.Parse(r["tknoa"].ToString());
					ltkco=long.Parse(r["tkcoa"].ToString());
					lmtmno=long.Parse(r["mtmno"].ToString());
					lmtmco=long.Parse(r["mtmco"].ToString());
					decimal st=decimal.Parse(r["stien"].ToString());
					stien.Text=st.ToString(format_sotien);
					st=decimal.Parse(r["nguyente"].ToString());
					nguyente.Text=st.ToString(format_sotien);
					ngoaite.SelectedValue=int.Parse(r["ngoaite"].ToString());
					st=decimal.Parse(r["tygia"].ToString());
					tygia.Text=st.ToString(format_sotien);
					noidung.Text=r["noidung"].ToString();
					mapt.SelectedValue=r["mapt"].ToString();
					capphat.SelectedValue=r["capphat"].ToString();
					DataRow r1=a.getrowbyid(dttk,"id="+ltkno);
					mtmno.Text=mtmco.Text="";
					if (r1!=null)
					{
						tkno.Text=r1["stk"].ToString();
						ttkno.Text=r1["ttk"].ToString();
					}
					load_mtm(tkno.Text,mtmno,kmno);
					load_mapt();
					if (lmtmno!=0)
					{
						r1=a.getrowbyid(dtmtm,"id="+lmtmno);
						if (r1!=null)
							mtmno.Text=r1["stk"].ToString();
					}
					kmno.SelectedValue=int.Parse(r["kmno"].ToString());
					kmno2.SelectedValue=int.Parse(r["kmno2"].ToString());
					kmno3.SelectedValue=int.Parse(r["kmno3"].ToString());
					kmno4.SelectedValue=int.Parse(r["kmno4"].ToString());
					r1=a.getrowbyid(dttk,"id="+ltkco);
					if (r1!=null)
					{
						tkco.Text=r1["stk"].ToString();
						ttkco.Text=r1["ttk"].ToString();
					}
					load_mtm(tkco.Text,mtmco,kmco);
					load_mapt();
					if (lmtmco!=0)
					{
						r1=a.getrowbyid(dtmtm,"id="+lmtmco);
						if (r1!=null)
							mtmco.Text=r1["stk"].ToString();
					}					
					kmco.SelectedValue=int.Parse(r["kmco"].ToString());
					kmco2.SelectedValue=int.Parse(r["kmco2"].ToString());
					kmco3.SelectedValue=int.Parse(r["kmco3"].ToString());
					kmco4.SelectedValue=int.Parse(r["kmco4"].ToString());
					stt.Text=r["ctgs"].ToString();
					s_thangqt=r["thangqt"].ToString();
					mapt.SelectedValue=int.Parse(r["mapt"].ToString());
					tonghop.Checked=r["tonghop"].ToString()=="1";
				}
			}
			catch{emp_detail();}
		}

		public Color MyGetColorRowCol(int row, int col)
		{
			if (this.dataGrid1[row,15].ToString()=="0") return Color.Red;
			else return Color.Black;
		}

		public delegate Color delegateGetColorRowCol(int row, int col);
		public class DataGridColoredTextBoxColumn : DataGridTextBoxColumn
		{
			private delegateGetColorRowCol _getColorRowCol;
			private int _column;
			public DataGridColoredTextBoxColumn(delegateGetColorRowCol getcolorRowCol, int column)
			{
				_getColorRowCol = getcolorRowCol;
				_column = column;
			}
			protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
			{
				try
				{
					foreBrush = new SolidBrush(_getColorRowCol(rowNum, this._column));
					//backBrush = new SolidBrush(Color.GhostWhite);
				}
				catch{}
				finally
				{
					base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
				}
			}
		}

		private void AddGridTableStyle()
		{
			DataGridColoredTextBoxColumn TextCol;
			delegateGetColorRowCol de = new delegateGetColorRowCol(MyGetColorRowCol);
			DataGridTableStyle ts =new DataGridTableStyle();
			ts.MappingName = dtct.TableName;
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			ts.ReadOnly=false;
			ts.RowHeaderWidth=10;
						
			TextCol=new DataGridColoredTextBoxColumn(de, 0);
			TextCol.MappingName = "id";
			TextCol.HeaderText = "";
			TextCol.Width = 0;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 1);
			TextCol.MappingName = "stt";
			TextCol.HeaderText = "STT";
			TextCol.Width = 30;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 2);
			TextCol.MappingName = "tenlk";
			TextCol.HeaderText = "Khoản";
			TextCol.Width = 50;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 3);
			TextCol.MappingName = "noidung";
			TextCol.HeaderText = "Nội dung";
			TextCol.Width = 200;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 4);
			TextCol.MappingName = "stknoa";
			TextCol.HeaderText = "TK Nợ";
			TextCol.Width = 80;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 5);
			TextCol.MappingName = "stkmtmno";
			TextCol.HeaderText = "Mục/Tiểu mục Nợ";
			TextCol.Width = 50;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 6);
			TextCol.MappingName = "tenkmno";
			TextCol.HeaderText = "KM Nợ";
			TextCol.Width = 0;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 7);
			TextCol.MappingName = "stkcoa";
			TextCol.HeaderText = "TK Có";
			TextCol.Width = 80;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 8);
			TextCol.MappingName = "stkmtmco";
            TextCol.HeaderText = "Mục/Tiểu mục Có";
			TextCol.Width = 100;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 9);
			TextCol.MappingName = "tenkmco";
			TextCol.HeaderText = "KM Có";
			TextCol.Width = 0;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 10);
			TextCol.MappingName = "tenpt";
			TextCol.HeaderText = "Phân tích";
			TextCol.Width = 100;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 11);
			TextCol.MappingName = "mangoaite";
			TextCol.HeaderText = "Ngoại tệ";
			TextCol.Width = 30;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 12);
			TextCol.MappingName = "tygia";
			TextCol.HeaderText = "Tỷ giá";
			TextCol.Width = 50;
			TextCol.Format="###,###,###";
			TextCol.Alignment=HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 13);
			TextCol.MappingName = "nguyente";
			TextCol.HeaderText = "Nguyên tệ";
			TextCol.Width = 80;
			TextCol.Format=format_sotien;
			TextCol.Alignment=HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 14);
			TextCol.MappingName = "stien";
			TextCol.HeaderText = "Số tiền";
			TextCol.Width = 100;
			TextCol.Format=format_sotien;
			TextCol.Alignment=HorizontalAlignment.Right;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridColoredTextBoxColumn(de, 15);
			TextCol.MappingName = "tonghop";
			TextCol.HeaderText = "";
			TextCol.Width = 0;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);
		}


		private void sophieu_Validated(object sender, System.EventArgs e)
		{
			if (l_id!=0) return;
			try
			{
				r=a.getrowbyid(dtll,"soctg='"+soctg.Text+"'");
				if (r!=null)
				{
					MessageBox.Show("Số chứng từ đã nhập !",a.Msg);
					soctg.Focus();
				}
			}
			catch{}
		}

		private void cmbSophieu_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab) butMoi.Focus();
		}

		private void cmbSophieu_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==cmbSoctg)
			{
				try
				{
					l_id=long.Parse(cmbSoctg.SelectedValue.ToString());
				}
				catch{l_id=0;}
				load_head();
			}
		}

		private void load_head()
		{
			try
			{
				r=a.getrowbyid(dtll,"id="+l_id);
				if (r!=null)
				{
					nhom.SelectedValue=r["idbc"].ToString();
					hoatdong.SelectedValue=int.Parse(r["hoatdong"].ToString());
					lctug.SelectedValue=int.Parse(r["lctug"].ToString());
					soctg.Text=r["soctg"].ToString();
					ngayg.Text=r["ngayg"].ToString();
					ngaygs.Text=r["ngaygs"].ToString();
					chuong.SelectedValue=int.Parse(r["chuong"].ToString());
					nghiepvu.SelectedValue=int.Parse(r["nghiepvu"].ToString());
					tcnkp.SelectedValue=int.Parse(r["tcnkp"].ToString());
					cbnguonns.SelectedValue=int.Parse(r["idns"].ToString());
					noidunga.Text=r["noidung"].ToString();
					loaidt.SelectedValue=int.Parse(r["loaidt"].ToString());
					madt.Text=r["mavt"].ToString();
					tendt.Text=r["tendt"].ToString();
					diachi.Text=r["diachi"].ToString();
					sotk.Text=r["sotaikhoan"].ToString();
					sotkno.Text=r["accountno"].ToString();
					sotkco.Text=r["accountco"].ToString();
					tennhno.Text=r["tennhno"].ToString();
					tennhco.Text=r["tennhco"].ToString();
					if (tendt.Text=="")
					{
						tendt.Text=r["tendtk"].ToString();
						diachi.Text=r["diachik"].ToString();
					}
					tknoa.Text=r["stknoa"].ToString();
					ttknoa.Text=r["ttknoa"].ToString();
					tkcoa.Text=r["stkcoa"].ToString();
					ttkcoa.Text=r["ttkcoa"].ToString();
					loaibk.SelectedValue=int.Parse(r["loaibk"].ToString());
					hoadon.Text=r["sobk"].ToString();
					ngayhd.Text=r["ngaybk"].ToString();
					decimal st=(thuesuat.Text!="")?decimal.Parse(thuesuat.Text):0;
					thuesuat.Text=st.ToString("###,###.##");
					st=(tienthue.Text!="")?decimal.Parse(tienthue.Text):0;
					tienthue.Text=st.ToString(format_sotien);
					ctgs.Text=r["ctgs"].ToString();
					l_iddongthoi=long.Parse(r["iddongthoi"].ToString());
					l_hopdong=long.Parse(r["hopdong"].ToString());
					if (l_hopdong!=0)
					{
						foreach(DataRow r1 in a.get_data("select a.*,to_char(a.ngay,'mmyy') as mmyys from a_theodoihd a where a.id="+l_hopdong).Tables[0].Rows)
						{
							hopdong.Text=r1["sohd"].ToString();
							s_mmyyhd=(r1["mmyy"].ToString()!="")?r1["mmyy"].ToString():r1["mmyys"].ToString();
						}
					}
					else hopdong.Text="";
				}
			}
			catch{}
			load_grid();
			ref_text();
		}

		private void butKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void Filter_dmdt(string ten)
		{
			try
			{
				CurrencyManager cm= (CurrencyManager)BindingContext[listdt.DataSource];
				DataView dv=(DataView)cm.List;
				sql="tendt like '%"+ten.Trim()+"%'";
				if (loaidt.SelectedIndex!=0) sql+=" and loaidt="+int.Parse(loaidt.SelectedValue.ToString());
				dv.RowFilter=sql;				
			}
			catch{}
		}

		private void tendt_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listdt.Focus();
			else if (e.KeyCode==Keys.Enter)
			{
				if (listdt.Visible)	listdt.Focus();
				else SendKeys.Send("{Tab}");
			}
		}

		private void tendt_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==tendt && !diachi.Enabled)
			{
				Filter_dmdt(tendt.Text);
				listdt.BrowseToDanhmuc(tendt,madt,tknoa,50);
			}
		}

		private void ena_object(bool ena)
		{
			find.Enabled=!ena;
			soctg.Visible=ena;
			cmbSoctg.Visible=!ena;
			if (!bSophieu) soctg.Enabled=ena;
			nhom.Enabled=hoatdong.Enabled=lctug.Enabled=soctg.Enabled=ngayg.Enabled=ngaygs.Enabled=ctgs.Enabled=chuong.Enabled=nghiepvu.Enabled=ena;
			tcnkp.Enabled=noidunga.Enabled=loaidt.Enabled=madt.Enabled=tendt.Enabled=tknoa.Enabled=cbnguonns.Enabled=ena;
			tkcoa.Enabled=tt.Enabled=lk.Enabled=tkno.Enabled=tkco.Enabled=tonghop.Enabled=ena;
			mapt.Enabled=capphat.Enabled=noidung.Enabled=ngoaite.Enabled=stien.Enabled=ena;
			butHD.Enabled=butBangke.Enabled=butThem.Enabled=butXoa.Enabled=butLuu.Enabled=butBoqua.Enabled=ena;
			butMoi.Enabled=butSua.Enabled=butHuy.Enabled=butIn.Enabled=butKetthuc.Enabled=!ena;
			i_old=cmbSoctg.SelectedIndex;
		}

		private void sophieu()
		{
			if (lctug.SelectedIndex!=-1) 
			{
				string ma=dtloai.Rows[lctug.SelectedIndex]["mact"].ToString();
				if (bSophieu && dtloai.Rows[lctug.SelectedIndex]["sophieu"].ToString()=="1")
				{
					soctg.Enabled=false;
					if (bSophieu_nam)
						soctg.Text=ma+a.get_sophieu(s_mmyy,"soctg"," chucnang="+chucnang+" and lctug="+int.Parse(lctug.SelectedValue.ToString()),3,4)+"/"+s_mmyy.Substring(2);
					else 
						soctg.Text=ma+a.get_sophieu(s_mmyy,"soctg"," chucnang="+chucnang+" and lctug="+int.Parse(lctug.SelectedValue.ToString())+" and thanggs='"+s_mmyy.Substring(0,2)+"'",3,4)+"/"+s_mmyy.Substring(0,2);
				}
				else
				{
					soctg.Enabled=true;
					soctg.Text="";
				}
				DataRow r;
				tknoa.Text=ttknoa.Text=tkcoa.Text=ttkcoa.Text=tkno.Text=ttkno.Text=tkco.Text=ttkco.Text="";
				sotkno.Text=tennhno.Text=sotkco.Text=tennhco.Text="";
				if (dtloai.Rows[lctug.SelectedIndex]["tkno"].ToString()!="")
				{
					tkno.Text=tknoa.Text=dtloai.Rows[lctug.SelectedIndex]["tkno"].ToString();
					r=a.getrowbyid(dttk,"stk='"+tknoa.Text+"'");
					if (r!=null)
					{
						ttkno.Text=ttknoa.Text=r["ttk"].ToString();
						load_sotk(tknoa.Text,sotkno,tennhno);
					}
				}
				if (dtloai.Rows[lctug.SelectedIndex]["tkco"].ToString()!="")
				{
					tkco.Text=tkcoa.Text=dtloai.Rows[lctug.SelectedIndex]["tkco"].ToString();
					r=a.getrowbyid(dttk,"stk='"+tkcoa.Text+"'");
					if (r!=null)
					{
						ttkco.Text=ttkcoa.Text=r["ttk"].ToString();
						load_sotk(tkcoa.Text,sotkco,tennhco);
					}
				}
				if(dtnns.Rows.Count>0&& dtloai.Rows[lctug.SelectedIndex]["loai"].ToString()=="6")
				{
					cbnguonns.Enabled=true;
				}
				else
				{
					cbnguonns.Text="";
					cbnguonns.SelectedIndex=-1;
					//sua false = true
					cbnguonns.Enabled=true;
				}
			}
		}

		private void load_sotk(string stk,MaskedTextBox.MaskedTextBox tsotk,MaskedTextBox.MaskedTextBox tennh)
		{
			r=a.getrowbyid(dttk,"stk='"+stk+"'");
			if (r!=null)
			{
				r=a.getrowbyid(dtnh,"stk="+long.Parse(r["id"].ToString()));
				if (r!=null)
				{
					tsotk.Text=r["account"].ToString();
					tennh.Text=r["tennh"].ToString();
				}
			}
		}
		private void emp_head()
		{
			CurrencyManager cm= (CurrencyManager)BindingContext[cmbSoctg.DataSource];
			DataView dv=(DataView)cm.List;			
			dv.RowFilter="";
			l_hopdong=l_iddongthoi=l_id=0;
			ngayg.Text=ngaygs.Text=s_ngay;
			s_mmyyhd=ctgs.Text=noidunga.Text=madt.Text=tendt.Text=diachi.Text=tknoa.Text=ttknoa.Text=tkcoa.Text=ttkcoa.Text=cbnguonns.Text="";
			sotk.Text=sotkno.Text=sotkco.Text=tennhno.Text=tennhco.Text=hopdong.Text=hoadon.Text=ngayhd.Text=thuesuat.Text=tienthue.Text="";
			dsxoa.Clear();stt.Text=a.get_stt(dtct).ToString();
			sophieu();load_tygia();
			loaidt.SelectedIndex=0;
			lsokhoan.Text="TỔNG SỐ KHOẢN :"+dtct.Rows.Count.ToString();
		}
		
		private void emp_detail()
		{
			tt.Value=decimal.Parse(a.get_stt(dtct).ToString());
			tkno.Text=ttkno.Text=mtmno.Text=kmno.Text=kmno2.Text=kmno3.Text=kmno4.Text="";
			tkco.Text=ttkco.Text=mtmco.Text=kmco.Text=kmco2.Text=kmco3.Text=kmco4.Text="";
			noidung.Text=nguyente.Text=stien.Text=s_thangqt="";
			loaidt.SelectedIndex=0;
			kmno.SelectedIndex=kmno2.SelectedIndex=kmno3.SelectedIndex=kmno4.SelectedIndex=kmco.SelectedIndex=kmco2.SelectedIndex=kmco3.SelectedIndex=kmco4.SelectedIndex=mapt.SelectedIndex=-1;
			if (lctug.SelectedIndex!=-1) 
			{
				tkno.Text=ttkno.Text=tkco.Text=ttkco.Text="";
				if (dtloai.Rows[lctug.SelectedIndex]["tkno"].ToString()!="")
				{
					tkno.Text=dtloai.Rows[lctug.SelectedIndex]["tkno"].ToString();
					r=a.getrowbyid(dttk,"stk='"+tknoa.Text+"'");
					if (r!=null) ttkno.Text=r["ttk"].ToString();
				}
				if (dtloai.Rows[lctug.SelectedIndex]["tkco"].ToString()!="")
				{
					tkco.Text=dtloai.Rows[lctug.SelectedIndex]["tkco"].ToString();
					r=a.getrowbyid(dttk,"stk='"+tkcoa.Text+"'");
					if (r!=null) ttkco.Text=r["ttk"].ToString();
				}
				if(dtnns.Rows.Count>0&& dtloai.Rows[lctug.SelectedIndex]["loai"].ToString()=="6")
				{
					cbnguonns.SelectedIndex=0;
				}
				else
				{
					cbnguonns.SelectedIndex=-1;
					cbnguonns.Text="";
				}
			}
			mtmno.Enabled=mtmco.Enabled=kmno.Enabled=kmno2.Enabled=kmno3.Enabled=kmno4.Enabled=kmco.Enabled=kmco2.Enabled=kmco3.Enabled=kmco4.Enabled=mapt.Enabled=false;
			tonghop.Checked=true;noidung.Text=noidunga.Text;
			l_idct=0;
		}

		private void butMoi_Click(object sender, System.EventArgs e)
		{
			if (bKhoaso)
			{
				MessageBox.Show("Số liệu tháng "+s_mmyy.Substring(0,2)+" năm "+s_mmyy.Substring(2,2)+" đã khóa !\nNếu cần thay đổi thì vào mục khai báo hệ thống",a.Msg);
				return;
			}	
			//load
			ena_object(true);
			emp_head();
			emp_detail();
			dtct.Clear();
			dtold.Clear();
			if (soctg.Text!="")
			{
				emp_head();
				emp_detail();
				dtct.Clear();
			}
			bNew=true;
			nhom.Focus();
			
		}

		private void butSua_Click(object sender, System.EventArgs e)
		{
			if (cmbSoctg.Items.Count==0) return;
			if (bKhoaso)
			{
				MessageBox.Show("Số liệu tháng "+s_mmyy.Substring(0,2)+" năm "+s_mmyy.Substring(2,2)+" đã khóa !\nNếu cần thay đổi thì vào mục khai báo hệ thống",a.Msg);
				return;
			}
			l_id=long.Parse(cmbSoctg.SelectedValue.ToString());
			/*
			if (a.get_data("select * from "+user+".a_ctct"+s_mmyy.Substring(2)+" where ctgs<>0 and idct="+l_id).Tables[0].Rows.Count>0)
			{
				MessageBox.Show("Chứng từ "+soctg.Text+" đã lập chứng từ ghi sổ\nKhông được chỉnh sủa!",a.Msg);
				return;
			}*/
			s_sophieu=soctg.Text;
			ena_object(true);
			bNew=false;
			load_dt();
			dtold=dtct.Copy();
			dsxoa.Clear();
			ref_text();
			listmtm.Hide();
			tt.Focus();
		}
		private void load_dt()
		{
			if (loaidt.SelectedIndex!=-1)
			{
				madt.Enabled=int.Parse(dtloaidt.Rows[loaidt.SelectedIndex]["id"].ToString())!=-1;
				diachi.Enabled=!madt.Enabled;
			}
		}

		private bool KiemtraHead()
		{
			if (nhom.SelectedIndex==-1)
			{
				MessageBox.Show("Chọn nhóm !",a.Msg);
				nhom.Focus();
				return false;
			}
			if (soctg.Text=="")
			{
				MessageBox.Show("Nhập số chứng từ !",a.Msg);
				soctg.Focus();
				return false;
			}
			if (ngayg.Text=="")
			{
				MessageBox.Show("Nhập ngày chứng từ !",a.Msg);
				ngayg.Focus();
				return false;
			}
			if (ngaygs.Text=="")
			{
				MessageBox.Show("Nhập ngày hạch toán !",a.Msg);
				ngaygs.Focus();
				return false;
			}
			if (noidunga.Text=="")
			{
				MessageBox.Show("Nhập nội dung chứng từ !",a.Msg);
				noidunga.Focus();
				return false;
			}
			ltknoa=ltkcoa=lmadt=0;
			if (tknoa.Text!="")
			{
				r=a.getrowbyid(dttk,"stk='"+tknoa.Text+"'");
				if (r==null)
				{
					MessageBox.Show("Tài khoản nợ không hợp lệ !",a.Msg);
					tknoa.Focus();
					return false;
				}
				ltknoa=long.Parse(r["id"].ToString());
			}
			if (tkcoa.Text!="")
			{
				r=a.getrowbyid(dttk,"stk='"+tkcoa.Text+"'");
				if (r==null)
				{
					MessageBox.Show("Tài khoản có không hợp lệ !",a.Msg);
					tkcoa.Focus();
					return false;
				}
				ltkcoa=long.Parse(r["id"].ToString());
			}
			if (madt.Enabled)
			{
				if (madt.Text=="" || tendt.Text=="")
				{
					MessageBox.Show("Nhập đối tượng !",a.Msg);
					madt.Focus();
					return false;
				}
				r=a.getrowbyid(dtdt,"mavt='"+madt.Text+"'");
				if (r==null)
				{
					MessageBox.Show("Đối tượng không hợp lệ !",a.Msg);
					madt.Focus();
					return false;
				}
				lmadt=long.Parse(r["id"].ToString());
			}
			if (dtct.Rows.Count==0)
			{
				MessageBox.Show("Đề nghị chứng từ chi tiết !",a.Msg);
				butThem.Focus();
				return false;
			}
			if (!bNew)
			{
//				if (a.get_data("select * from "+user+".a_ctct"+s_mmyy.Substring(2)+" where ctgs<>0 and idct="+l_id).Tables[0].Rows.Count>0)
//				{
//					MessageBox.Show("Chứng từ "+soctg.Text+" đã lập chứng từ ghi sổ\nKhông được chỉnh sủa!",a.Msg);
//					return false;
//				}
				if (soctg.Text!=s_sophieu)
				{
					sql="select soctg from a_ct"+s_mmyy.Substring(2)+" where chucnang="+chucnang+" and lctug="+int.Parse(lctug.SelectedValue.ToString());
					sql+=" and soctg='"+soctg.Text+"'  and thanggs='"+s_mmyy.Substring(0,2)+"' and id<>"+l_id;
					if (a.get_data(sql).Tables[0].Rows.Count>0)
					{
						MessageBox.Show("Số chứng từ "+soctg.Text+" đã nhập !",a.Msg);
						soctg.Focus();
						return false;
					}
				}
			}
			if (l_hopdong!=0)
			{
				decimal st=(zstien.Text!="")?decimal.Parse(zstien.Text):0;
				string _sohd="",_ngay="";
				if (!bNew) 
				{
					foreach(DataRow r1 in a.get_data("select soctg,to_char(ngayg,'dd/mm/yyyy') as ngayg from "+user+".a_ct"+s_mmyy.Substring(2,2)+" where id="+l_id).Tables[0].Rows)
					{
						_sohd=r1["soctg"].ToString();_ngay=r1["ngayg"].ToString();
					}
				}
				decimal so=getstt(_sohd,_ngay);
				st+=getsotien(so);
				so=0;
				foreach(DataRow r1 in a.get_data("select stien from "+user+".a_theodoihd where id="+l_hopdong).Tables[0].Rows)
					so=decimal.Parse(r1["stien"].ToString());
				if (st>so)
				{
					string s="Số tiền chi không được vượt quá số tiền hóa đơn :"+hopdong.Text;
					if (s.IndexOf("{")==-1) s+="("+so.ToString("###,###,###,###,###")+")!";
					MessageBox.Show(s,a.Msg);
					dataGrid1.Focus();
					ref_text();
					return false;
				}
			}
			return true;
		}

		private bool KiemtraDetail()
		{
			ltkno=ltkco=lmtmno=lmtmco=0;
			if (tkno.Text=="")
			{
				MessageBox.Show("Nhập tài khoản nợ !",a.Msg);
				tkno.Focus();
				return false;
			}
			if (tkco.Text=="")
			{
				MessageBox.Show("Nhập tài khoản có !",a.Msg);
				tkco.Focus();
				return false;
			}
			r=a.getrowbyid(dttk,"stk='"+tkno.Text+"'");
			if (r==null)
			{
				MessageBox.Show("Tài khoản nợ không hợp lệ !",a.Msg);
				tkno.Focus();
				return false;
			}
			ltkno=long.Parse(r["id"].ToString());
			r=a.getrowbyid(dttk,"stk='"+tkco.Text+"'");
			if (r==null)
			{
				MessageBox.Show("Tài khoản có không hợp lệ !",a.Msg);
				tkco.Focus();
				return false;
			}
			ltkco=long.Parse(r["id"].ToString());
			if (mtmno.Enabled && mtmno.Text=="")
			{
				MessageBox.Show("Nhập mục tiểu mục nợ !",a.Msg);
				mtmno.Focus();
				return false;
			}
			if (mtmno.Text!="")
			{
				r=a.getrowbyid(dtmtm,"stk='"+mtmno.Text+"'");
				if (r==null)
				{
					MessageBox.Show("Mục tiểu mục nợ không hợp lệ !",a.Msg);
					mtmno.Focus();
					return false;
				}
				lmtmno=long.Parse(r["id"].ToString());
			}
			if (mtmco.Enabled && mtmco.Text=="")
			{
				MessageBox.Show("Nhập mục tiểu mục có !",a.Msg);
				mtmco.Focus();
				return false;
			}
			if (mtmco.Text!="")
			{
				r=a.getrowbyid(dtmtm,"stk='"+mtmco.Text+"'");
				if (r==null)
				{
					MessageBox.Show("Mục tiểu mục có không hợp lệ !",a.Msg);
					mtmco.Focus();
					return false;
				}
				lmtmco=long.Parse(r["id"].ToString());
			}
			if (noidunga.Text=="")
			{
				MessageBox.Show("Nhập nội dung chứng từ !",a.Msg);
				noidunga.Focus();
				return false;
			}
			dstien=(stien.Text!="")?decimal.Parse(stien.Text):0;
			if (dstien==0)
			{
				MessageBox.Show("Nhập số tiền !",a.Msg);
				if (nguyente.Enabled) nguyente.Focus();
				else stien.Focus();
				return false;
			}
			dnguyente=(nguyente.Text!="")?decimal.Parse(nguyente.Text):0;
			return true;
		}

		private void butLuu_Click(object sender, System.EventArgs e)
		{
			string s_loaidt="-1";
			int manns=0;
			manns=cbnguonns.Text!=""?int.Parse(cbnguonns.SelectedValue.ToString()):0;
			if (madt.Text!="") s_loaidt=a.getrowbyid(dtdt,"mavt='"+madt.Text.Trim()+"'")["loaidt"].ToString().Trim();
			else if(loaidt.SelectedValue.ToString()=="-1")s_loaidt="-1";
			if (tkno.Text!="" && tkco.Text!="") upd_table(dtct,"+");
			dtct.AcceptChanges();
			if (!KiemtraHead()) return;
			if (bNew && bSophieu && dtloai.Rows[lctug.SelectedIndex]["sophieu"].ToString()=="1")
			{
				string ma=dtloai.Rows[lctug.SelectedIndex]["mact"].ToString();
				if (bSophieu_nam)
					soctg.Text=ma+a.get_sophieu(s_mmyy,"soctg"," chucnang="+chucnang+" and lctug="+int.Parse(lctug.SelectedValue.ToString()),3,4)+"/"+s_mmyy.Substring(2);
				else 
					soctg.Text=ma+a.get_sophieu(s_mmyy,"soctg"," chucnang="+chucnang+" and lctug="+int.Parse(lctug.SelectedValue.ToString())+" and thanggs='"+s_mmyy.Substring(0,2)+"'",3,4)+"/"+s_mmyy.Substring(0,2);
				soctg.Update();
			}
			i_old=(bNew)?0:1;
			l_id=(bNew)?a.getIdct():l_id;
            l_iddongthoi = (l_iddongthoi == 0) ? a.getIdct() : l_iddongthoi;
			bool bFound=false;
			DataRow r2;
			long ltkcoaht=0;
			foreach(DataRow r1 in dtct.Rows)
			{
				bFound=timtkdt_ng(s_stkdt,r1["tkcoa"].ToString().Trim());
				if (bFound)
				{
					r2=a.getrowbyid(dtht,"stk="+long.Parse(r1["tkcoa"].ToString()));
					if (r2!=null) ltkcoaht=long.Parse(r2["stkch"].ToString());
					break;				
				}
			}
			string _sohd="",_ngay="";
			itable = a.tableid("","a_ct"+s_mmyy.Substring(2));
			if (bNew) a.upd_eve_tables(itable, i_userid, "ins");
			else
			{
				a.upd_eve_tables(itable, i_userid, "upd");
				a.upd_eve_upd_del(itable, i_userid, "upd",a.fields("a_ct"+s_mmyy.Substring(2),"id="+l_id));
				if (l_hopdong!=0)
				{
					foreach(DataRow r1 in a.get_data("select soctg,to_char(ngayg,'dd/mm/yyyy') as ngayg from "+user+".a_ct"+s_mmyy.Substring(2,2)+" where id="+l_id).Tables[0].Rows)
					{
						_sohd=r1["soctg"].ToString();_ngay=r1["ngayg"].ToString();
					}
				}
			}
//			if (!a.updCt(s_mmyy,l_id,int.Parse(nhom.SelectedValue.ToString()),"",int.Parse(chuong.SelectedValue.ToString()),chucnang,int.Parse(hoatdong.SelectedValue.ToString()),int.Parse(lctug.SelectedValue.ToString()),soctg.Text,ngayg.Text,ngaygs.Text,noidunga.Text,ltknoa,ltkcoa,int.Parse(s_loaidt),lmadt,(zstien.Text!="")?decimal.Parse(zstien.Text):0,(znguyente.Text!="")?decimal.Parse(znguyente.Text):0,s_mmyy.Substring(0,2),int.Parse(nghiepvu.SelectedValue.ToString()),int.Parse(loaibk.SelectedValue.ToString()),int.Parse(tcnkp.SelectedValue.ToString()),l_hopdong,ctgs.Text,l_iddongthoi,i_userid))
//			{
//				MessageBox.Show("Không cập nhật được thông tin chứng từ !",a.Msg);
//				return;
//			}
            stk_hachtoan = a.get_data("select * from a_hachtoan" + s_mmyy.Substring(2, 2) + " where loai=3").Tables[0];
            foreach (DataRow r1 in stk_hachtoan.Rows)
            {
                if (ltkcoa.ToString() != r1["stk"].ToString().Trim())
                {
                    foreach (DataRow r_ in a.get_data("select iddongthoi from " + user + ".a_ct" + s_mmyy.Substring(2, 2) + " where id=" + l_id).Tables[0].Rows)
                    {
                        a.execute_data("delete from a_ct" + s_mmyy.Substring(2, 2) + " where id = " + r_["iddongthoi"].ToString() + "");
                        a.execute_data("delete from a_ctct" + s_mmyy.Substring(2) + " where idct=" + r_["iddongthoi"].ToString() + "");
                        a.execute_data("update a_ct" + s_mmyy.Substring(2, 2) + " set iddongthoi=0 where id =" + l_id);
                        l_iddongthoi = 0;
                    }
                }
            }
			if (!a.updCtnghang(s_mmyy,l_id,int.Parse(nhom.SelectedValue.ToString()),"",int.Parse(chuong.SelectedValue.ToString()),chucnang,int.Parse(hoatdong.SelectedValue.ToString()),int.Parse(lctug.SelectedValue.ToString()),soctg.Text,ngayg.Text,ngaygs.Text,noidunga.Text,ltknoa,ltkcoa,int.Parse(s_loaidt),lmadt,(zstien.Text!="")?decimal.Parse(zstien.Text):0,(znguyente.Text!="")?decimal.Parse(znguyente.Text):0,s_mmyy.Substring(0,2),int.Parse(nghiepvu.SelectedValue.ToString()),int.Parse(loaibk.SelectedValue.ToString()),int.Parse(tcnkp.SelectedValue.ToString()),l_hopdong,ctgs.Text,l_iddongthoi,i_userid,manns))
			{
				MessageBox.Show("Không cập nhật được thông tin chứng từ !",a.Msg);
				return;
			}
			if (l_hopdong!=0)
			{
				decimal so=getstt(_sohd,_ngay);
				a.upd_theodoihdct(l_hopdong,so,soctg.Text,ngayg.Text,tknoa.Text,tkcoa.Text,(zstien.Text!="")?decimal.Parse(zstien.Text):0,noidunga.Text,i_userid);
				if (s_mmyyhd!="") a.upd_thanhtoanct(s_mmyyhd,l_hopdong,so,soctg.Text,ngayg.Text,tknoa.Text,tkcoa.Text,(zstien.Text!="")?decimal.Parse(zstien.Text):0,noidunga.Text,i_userid);
				so=getsotien(0);
				a.execute_data("update "+user+".a_theodoihd set stdatra="+so+" where id="+l_hopdong);
				if (s_mmyyhd!="") a.execute_data("update "+user+"d"+s_mmyyhd+".d_thanhtoan set datra="+so+" where id="+l_hopdong);
			}
			if (!madt.Enabled) a.updCtk(s_mmyy,l_id,tendt.Text,diachi.Text);
			itable = a.tableid("", "a_ctct"+s_mmyy.Substring(2));
			if (!bNew)
			{
				foreach(DataRow r1 in dsxoa.Tables[0].Rows)
				{
					a.upd_eve_tables(itable, i_userid, "del");
					a.upd_eve_upd_del(itable, i_userid, "del",a.fields("a_ctct"+s_mmyy.Substring(2),"id="+long.Parse(r1["id"].ToString())));
					a.execute_data("delete from a_ctct"+s_mmyy.Substring(2)+" where id="+long.Parse(r1["id"].ToString()));
					if (l_iddongthoi!=0)
					{
						if (s_stkdt.IndexOf(r1["tkcoa"].ToString().Trim()+",")!=-1)
						{
							r2=a.getrowbyid(dtht,"stk="+long.Parse(r1["tkcoa"].ToString()));
							if (r2!=null)
								a.execute_data("delete from a_ctct"+s_mmyy.Substring(2)+" where idct="+l_iddongthoi+" and stt="+long.Parse(r1["stt"].ToString()));
						}
					}
				}
				foreach(DataRow r1 in dtold.Rows)
				{
					if (r1["tonghop"].ToString()=="1")
					{
						a.updSodu("a_sd",a.delete,s_mmyy,long.Parse(nhom.SelectedValue.ToString()),long.Parse(chuong.SelectedValue.ToString()),l_hopdong,
							long.Parse(r1["lk"].ToString()),long.Parse(nghiepvu.SelectedValue.ToString()),lmadt,
							long.Parse(r1["tknoa"].ToString()),long.Parse(r1["tkcoa"].ToString()),long.Parse(r1["kmno"].ToString()),
							long.Parse(r1["kmco"].ToString()),long.Parse(r1["kmno2"].ToString()),long.Parse(r1["kmco2"].ToString()),
							long.Parse(r1["kmno3"].ToString()),long.Parse(r1["kmco3"].ToString()),long.Parse(r1["kmno4"].ToString()),long.Parse(r1["kmco4"].ToString()),
							long.Parse(r1["mtmno"].ToString()),long.Parse(r1["mtmco"].ToString()),
							long.Parse(hoatdong.SelectedValue.ToString()),decimal.Parse(r1["stien"].ToString()));
						if (r1["thangqt"].ToString()!="")
						{
							a.updSodu("a_sdc",a.delete,r1["thangqt"].ToString()+s_mmyy.Substring(2),long.Parse(nhom.SelectedValue.ToString()),
								long.Parse(chuong.SelectedValue.ToString()),
								l_hopdong,long.Parse(r1["lk"].ToString()),
								long.Parse(nghiepvu.SelectedValue.ToString()),lmadt,long.Parse(r1["tknoa"].ToString()),
								long.Parse(r1["tkcoa"].ToString()),long.Parse(r1["kmno"].ToString()),long.Parse(r1["kmco"].ToString()),long.Parse(r1["kmno2"].ToString()),long.Parse(r1["kmco2"].ToString()),
								long.Parse(r1["kmno3"].ToString()),long.Parse(r1["kmco3"].ToString()),long.Parse(r1["kmno4"].ToString()),long.Parse(r1["kmco4"].ToString()),
								long.Parse(r1["mtmno"].ToString()),long.Parse(r1["mtmco"].ToString()),
								long.Parse(hoatdong.SelectedValue.ToString()),decimal.Parse(r1["stien"].ToString()));
						}
						if (a.bChophanbo(long.Parse(r1["tknoa"].ToString()),long.Parse(r1["tkcoa"].ToString())))
							a.updPhanbo("a_phanbochua",a.delete,l_id,long.Parse(r1["id"].ToString()),long.Parse(lctug.SelectedValue.ToString()),
								soctg.Text,ngayg.Text,long.Parse(r1["tknoa"].ToString()),long.Parse(r1["tkcoa"].ToString()),
                                "",r1["noidung"].ToString(),1,decimal.Parse(r1["stien"].ToString()),
								long.Parse(nghiepvu.SelectedValue.ToString()),s_mmyy,i_userid);

						if (l_iddongthoi!=0)
						{
							if (s_stkdt.IndexOf(r1["tkcoa"].ToString().Trim()+",")!=-1)
							{
								r2=a.getrowbyid(dtht,"stk="+long.Parse(r1["tkcoa"].ToString()));
								if (r2!=null)
								{
									a.updSodu("a_sd",a.delete,s_mmyy,long.Parse(nhom.SelectedValue.ToString()),long.Parse(chuong.SelectedValue.ToString()),l_hopdong,
										long.Parse(r1["lk"].ToString()),long.Parse(nghiepvu.SelectedValue.ToString()),lmadt,
										0,long.Parse(r2["stkch"].ToString()),0,long.Parse(r1["kmco"].ToString()),
										0,long.Parse(r1["kmco2"].ToString()),0,long.Parse(r1["kmco3"].ToString()),
										0,long.Parse(r1["kmco4"].ToString()),0,long.Parse(r1["mtmco"].ToString()),
										long.Parse(hoatdong.SelectedValue.ToString()),decimal.Parse(r1["stien"].ToString()));
									if (r1["thangqt"].ToString()!="")
									{
										a.updSodu("a_sdc",a.delete,r1["thangqt"].ToString()+s_mmyy.Substring(2),long.Parse(nhom.SelectedValue.ToString()),long.Parse(chuong.SelectedValue.ToString()),
											l_hopdong,long.Parse(r1["lk"].ToString()),
											long.Parse(nghiepvu.SelectedValue.ToString()),lmadt,
											0,long.Parse(r2["stkch"].ToString()),
											0,long.Parse(r1["kmco"].ToString()),
											0,long.Parse(r1["kmco2"].ToString()),
											0,long.Parse(r1["kmco3"].ToString()),
											0,long.Parse(r1["kmco4"].ToString()),
											0,long.Parse(r1["mtmco"].ToString()),
											long.Parse(hoatdong.SelectedValue.ToString()),decimal.Parse(r1["stien"].ToString()));
									}
								}
							}
						}

					}
				}
			}
			if (bFound)
			{	
				//l_iddongthoi=(l_iddongthoi==0)?a.getIdct():l_iddongthoi;
				//l_iddongthoi=(bNew)?a.getIdct():l_iddongthoi;
				a.updCt(s_mmyy,l_iddongthoi,int.Parse(nhom.SelectedValue.ToString()),"",int.Parse(chuong.SelectedValue.ToString()),chucnang,int.Parse(hoatdong.SelectedValue.ToString()),lctug_dutoanns,soctg.Text,ngayg.Text,ngaygs.Text,noidunga.Text,0,ltkcoaht,int.Parse(s_loaidt),lmadt,(zstien.Text!="")?decimal.Parse(zstien.Text):0,(znguyente.Text!="")?decimal.Parse(znguyente.Text):0,s_mmyy.Substring(0,2),int.Parse(nghiepvu.SelectedValue.ToString()),int.Parse(loaibk.SelectedValue.ToString()),int.Parse(tcnkp.SelectedValue.ToString()),l_hopdong,ctgs.Text,l_iddongthoi,i_userid);
				if (!madt.Enabled) a.updCtk(s_mmyy,l_iddongthoi,tendt.Text,diachi.Text);
			}
			long idctdt=0;
			foreach(DataRow r1 in dtct.Rows)
			{
				if (a.get_data("select * from a_ctct"+s_mmyy.Substring(2)+" where id=" + long.Parse(r1["id"].ToString())).Tables[0].Rows.Count != 0)
				{
					a.upd_eve_tables(itable, i_userid, "upd");
					a.upd_eve_upd_del(itable, i_userid, "upd",a.fields("a_ctct"+s_mmyy.Substring(2),"id="+long.Parse(r1["id"].ToString())));
				}
				else a.upd_eve_tables(itable, i_userid, "ins");
				a.updCtct(s_mmyy,long.Parse(r1["id"].ToString()),l_id,int.Parse(r1["stt"].ToString()),int.Parse(r1["lk"].ToString()),
					r1["noidung"].ToString(),long.Parse(r1["tknoa"].ToString()),long.Parse(r1["tkcoa"].ToString()),
					long.Parse(r1["kmno"].ToString()),long.Parse(r1["kmco"].ToString()),
					long.Parse(r1["kmno2"].ToString()),long.Parse(r1["kmco2"].ToString()),
					long.Parse(r1["kmno3"].ToString()),long.Parse(r1["kmco3"].ToString()),
					long.Parse(r1["kmno4"].ToString()),long.Parse(r1["kmco4"].ToString()),
					long.Parse(r1["mtmno"].ToString()),
					long.Parse(r1["mtmco"].ToString()),decimal.Parse(r1["stien"].ToString()),decimal.Parse(r1["nguyente"].ToString()),
					long.Parse(r1["ngoaite"].ToString()),decimal.Parse(r1["tygia"].ToString()),int.Parse(r1["tonghop"].ToString()),
					long.Parse(r1["mapt"].ToString()),int.Parse(r1["capphat"].ToString()),int.Parse(lctug.SelectedValue.ToString()),
					soctg.Text,ngayg.Text,int.Parse(chuong.SelectedValue.ToString()),l_hopdong,
					int.Parse(nghiepvu.SelectedValue.ToString()),lmadt,int.Parse(hoatdong.SelectedValue.ToString()),i_userid);
				
				r2=a.getrowbyid(dtht,"stk="+long.Parse(r1["tkcoa"].ToString()));
				if (bFound && r2!=null)
				{
					if (!bNew)
					{
						idctdt=0;
						foreach(DataRow r3 in a.get_data("select * from a_ctct"+s_mmyy.Substring(2)+" where idct="+l_iddongthoi+" and stt="+long.Parse(r1["stt"].ToString())).Tables[0].Rows)
							idctdt=long.Parse(r3["id"].ToString());
						idctdt=(idctdt==0)?a.getIdctct():idctdt;
					}
					else idctdt=a.getIdctct();
					a.updCtct(s_mmyy,idctdt,l_iddongthoi,int.Parse(r1["stt"].ToString()),int.Parse(r1["lk"].ToString()),
						r1["noidung"].ToString(),0,long.Parse(r2["stkch"].ToString()),
						0,long.Parse(r1["kmco"].ToString()),
						0,long.Parse(r1["kmco2"].ToString()),
						0,long.Parse(r1["kmco3"].ToString()),
						0,long.Parse(r1["kmco4"].ToString()),
						0,long.Parse(r1["mtmco"].ToString()),decimal.Parse(r1["stien"].ToString()),decimal.Parse(r1["nguyente"].ToString()),
						long.Parse(r1["ngoaite"].ToString()),decimal.Parse(r1["tygia"].ToString()),int.Parse(r1["tonghop"].ToString()),
						long.Parse(r1["mapt"].ToString()),int.Parse(r1["capphat"].ToString()),int.Parse(lctug.SelectedValue.ToString()),
						soctg.Text,ngayg.Text,int.Parse(chuong.SelectedValue.ToString()),l_hopdong,
						int.Parse(nghiepvu.SelectedValue.ToString()),lmadt,int.Parse(hoatdong.SelectedValue.ToString()),i_userid);
				}
				if (r1["tonghop"].ToString()=="1")
				{
					a.updSodu("a_sd",a.insert,s_mmyy,long.Parse(nhom.SelectedValue.ToString()),long.Parse(chuong.SelectedValue.ToString()),l_hopdong,
						long.Parse(r1["lk"].ToString()),long.Parse(nghiepvu.SelectedValue.ToString()),lmadt,
						long.Parse(r1["tknoa"].ToString()),long.Parse(r1["tkcoa"].ToString()),
						long.Parse(r1["kmno"].ToString()),long.Parse(r1["kmco"].ToString()),
						long.Parse(r1["kmno2"].ToString()),long.Parse(r1["kmco2"].ToString()),
						long.Parse(r1["kmno3"].ToString()),long.Parse(r1["kmco3"].ToString()),
						long.Parse(r1["kmno4"].ToString()),long.Parse(r1["kmco4"].ToString()),
						long.Parse(r1["mtmno"].ToString()),long.Parse(r1["mtmco"].ToString()),
						long.Parse(hoatdong.SelectedValue.ToString()),decimal.Parse(r1["stien"].ToString()));

					if (bFound && r2!=null)
					{
						a.updSodu("a_sd",a.insert,s_mmyy,long.Parse(nhom.SelectedValue.ToString()),long.Parse(chuong.SelectedValue.ToString()),l_hopdong,
							long.Parse(r1["lk"].ToString()),long.Parse(nghiepvu.SelectedValue.ToString()),lmadt,
							0,long.Parse(r2["stkch"].ToString()),0,long.Parse(r1["kmco"].ToString()),
							0,long.Parse(r1["kmco2"].ToString()),0,long.Parse(r1["kmco3"].ToString()),
							0,long.Parse(r1["kmco4"].ToString()),0,long.Parse(r1["mtmco"].ToString()),
							long.Parse(hoatdong.SelectedValue.ToString()),decimal.Parse(r1["stien"].ToString()));
					}
					if (a.bChophanbo(long.Parse(r1["tknoa"].ToString()),long.Parse(r1["tkcoa"].ToString())))
						a.updPhanbo("a_phanbochua",a.insert,l_id,long.Parse(r1["id"].ToString()),long.Parse(lctug.SelectedValue.ToString()),
							soctg.Text,ngayg.Text,long.Parse(r1["tknoa"].ToString()),long.Parse(r1["tkcoa"].ToString()),
							"",r1["noidung"].ToString(),1,decimal.Parse(r1["stien"].ToString()),
							long.Parse(nghiepvu.SelectedValue.ToString()),s_mmyy,i_userid);
				}
			}
			a.updDtsd("",s_mmyy,i_userid);
			a.updrec_ct(dtll,l_id,int.Parse(nhom.SelectedValue.ToString()),"",int.Parse(chuong.SelectedValue.ToString()),int.Parse(hoatdong.SelectedValue.ToString()),
				int.Parse(lctug.SelectedValue.ToString()),soctg.Text,ngayg.Text,ngaygs.Text,noidung.Text,
				ltknoa,ltkcoa,int.Parse(s_loaidt),lmadt,(zstien.Text!="")?decimal.Parse(zstien.Text):0,
				(znguyente.Text!="")?decimal.Parse(znguyente.Text):0,s_mmyy.Substring(0,2),int.Parse(nghiepvu.SelectedValue.ToString()),
				(loaibk.SelectedIndex!=-1)?int.Parse(loaibk.SelectedValue.ToString()):0,int.Parse(tcnkp.SelectedValue.ToString()),
				0,l_hopdong,ctgs.Text,tknoa.Text,tkcoa.Text,ttknoa.Text,ttkcoa.Text,
				madt.Text,tendt.Text,diachi.Text,hoadon.Text,0,"",hoadon.Text,ngayhd.Text,(thuesuat.Text!="")?decimal.Parse(thuesuat.Text):0,
				(tienthue.Text!="")?decimal.Parse(tienthue.Text):0,(madt.Enabled)?"":tendt.Text,(madt.Enabled)?"":diachi.Text,
				hoatdong.Text,sotk.Text,sotkno.Text,sotkco.Text,tennhno.Text,tennhco.Text,"",l_iddongthoi);
			try
			{
				if (i_old==0 && dtll.Rows.Count>0) cmbSoctg.SelectedIndex=dtll.Rows.Count-1;
			}
			catch{}
			tongcong();
			ena_object(false);
			kmno.Enabled=kmco.Enabled=kmno2.Enabled=kmco2.Enabled=kmno3.Enabled=kmco3.Enabled=kmno4.Enabled=kmco4.Enabled=soctg.Enabled=diachi.Enabled=false;
			butMoi.Focus();
		}

		private decimal getstt(string sohd,string ngay)
		{
			if (sohd!="" && ngay!="") sql="select stt from "+user+".a_theodoihdct where id="+l_hopdong+" and so='"+sohd+"' and to_char(ngay,'dd/mm/yyyy')='"+ngay+"'";
			else 	sql="select max(stt)+1 as stt from "+user+".a_theodoihdct where id="+l_hopdong;
			DataTable tmp=a.get_data(sql).Tables[0];
			if (tmp.Rows.Count>0)
			{
				if (tmp.Rows[0]["stt"].ToString()!="") return decimal.Parse(tmp.Rows[0]["stt"].ToString());
				else return 1;
			}
			else return 1;
		}

		private decimal getsotien(decimal stt)
		{
			sql="select sum(sotien) as sotien from "+user+".a_theodoihdct where id="+l_hopdong;
			if (stt!=0) sql+=" and stt<>"+stt;
			DataTable tmp=a.get_data(sql).Tables[0];
			if (tmp.Rows[0]["sotien"].ToString()!="") return decimal.Parse(tmp.Rows[0]["sotien"].ToString());
			else return 0;
		}

		private void butBoqua_Click(object sender, System.EventArgs e)
		{
			cmbSoctg.SelectedIndex=i_old;
			try
			{
				l_id=long.Parse(cmbSoctg.SelectedValue.ToString());
			}
			catch{l_id=0;}
			load_head();
			ena_object(false);
			kmno.Enabled=kmco.Enabled=kmno2.Enabled=kmco2.Enabled=kmno3.Enabled=kmco3.Enabled=kmno4.Enabled=kmco4.Enabled=soctg.Enabled=diachi.Enabled=false;
			listmtm.Hide();
			butMoi.Focus();
		}

		private void ngayg_Validated(object sender, System.EventArgs e)
		{
			if (ngayg.Text=="") return;
			ngayg.Text=ngayg.Text.Trim();
			if (!a.bNgay(ngayg.Text))
			{
				MessageBox.Show("Ngày không hợp lệ !",a.Msg);
				ngayg.Focus();
				return;
			}
			ngayg.Text=a.Ktngaygio(ngayg.Text,10);
			if (ngayg.Text!=s_ngayg)
			{
				if (!a.ngay(a.StringToDate(ngayg.Text.Substring(0,10)),DateTime.Now,i_songay))
				{
					MessageBox.Show("Ngày không hợp lệ so với khai báo hệ thống ("+i_songay.ToString()+")!",a.Msg);
					ngayg.Focus();
					return;
				}
			}
		}

		private void ngaygs_Validated(object sender, System.EventArgs e)
		{
			if (ngaygs.Text=="") return;
			ngaygs.Text=ngaygs.Text.Trim();
			if (!a.bNgay(ngaygs.Text))
			{
				MessageBox.Show("Ngày không hợp lệ !",a.Msg);
				ngaygs.Focus();
				return;
			}
			ngaygs.Text=a.Ktngaygio(ngaygs.Text,10);
			if (ngaygs.Text!=s_ngaygs)
			{
				if (!a.ngay(a.StringToDate(ngaygs.Text.Substring(0,10)),DateTime.Now,i_songay))
				{
					MessageBox.Show("Ngày không hợp lệ so với khai báo hệ thống ("+i_songay.ToString()+")!",a.Msg);
					ngaygs.Focus();
					return;
				}
			}
		}

		private void butThem_Click(object sender, System.EventArgs e)
		{
			if (!upd_table(dtct,"+")) return;
			emp_detail();
			lk.Focus();
		}

		private void butXoa_Click(object sender, System.EventArgs e)
		{
			if (!upd_table(dsxoa.Tables[0],"-")) return;
			a.delrec(dtct,"id="+l_idct);
			dtct.AcceptChanges();
			if (dtct.Rows.Count==0) emp_detail();
			else ref_text();
		}

		private bool upd_table(DataTable dt,string ttu)
		{
			if (!KiemtraDetail()) return false;
			decimal _stien=(stien.Text!="")?decimal.Parse(stien.Text):0;
			decimal _nguyente=(nguyente.Text!="")?decimal.Parse(nguyente.Text):0;
			if (l_idct==0) l_idct=a.getIdctct();
			a.updrec_ctct(dt,l_idct,tt.Value,int.Parse(lk.SelectedValue.ToString()),noidung.Text,ltkno,ltkco,
				(kmno.SelectedIndex!=-1)?int.Parse(kmno.SelectedValue.ToString()):0,(kmco.SelectedIndex!=-1)?int.Parse(kmco.SelectedValue.ToString()):0,
				(kmno2.SelectedIndex!=-1)?int.Parse(kmno2.SelectedValue.ToString()):0,(kmco2.SelectedIndex!=-1)?int.Parse(kmco2.SelectedValue.ToString()):0,
				(kmno3.SelectedIndex!=-1)?int.Parse(kmno3.SelectedValue.ToString()):0,(kmco3.SelectedIndex!=-1)?int.Parse(kmco3.SelectedValue.ToString()):0,
				(kmno4.SelectedIndex!=-1)?int.Parse(kmno4.SelectedValue.ToString()):0,(kmco4.SelectedIndex!=-1)?int.Parse(kmco4.SelectedValue.ToString()):0,
				lmtmno,lmtmco,_stien,_nguyente,
				(ngoaite.SelectedIndex!=-1)?long.Parse(ngoaite.SelectedValue.ToString()):0,(tygia.Text!="")?decimal.Parse(tygia.Text):0,
				(ngoaite.SelectedIndex!=-1)?ngoaite.Text:"",(tonghop.Checked)?1:0,(mapt.SelectedIndex!=-1)?long.Parse(mapt.SelectedValue.ToString()):0,
				stt.Text,lk.Text,tkno.Text,tkco.Text,mtmno.Text,mtmco.Text,(mapt.SelectedIndex!=-1)?mapt.Text:"",
				(kmno.SelectedIndex!=-1)?kmno.Text:"",(kmco.SelectedIndex!=-1)?kmco.Text:"",
				(capphat.SelectedIndex!=-1)?int.Parse(capphat.SelectedValue.ToString()):0,(capphat.SelectedIndex!=-1)?capphat.Text:"",s_thangqt);
			tongcong();
			dt.AcceptChanges();
			return true;
		}


		private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
		{
			ref_text();
		}

		private void stien_Validated(object sender, System.EventArgs e)
		{
			try
			{
				decimal _sotien=(stien.Text!="")?decimal.Parse(stien.Text):0;
				stien.Text=_sotien.ToString(format_sotien);
			}
			catch{}
		}

		private void nguyente_Validated(object sender, System.EventArgs e)
		{
			try
			{
				decimal _nguyente=(nguyente.Text!="")?decimal.Parse(nguyente.Text):0;
				nguyente.Text=_nguyente.ToString(format_sotien);
				decimal st=_nguyente*((tygia.Text!="")?decimal.Parse(tygia.Text):1);
				stien.Text=st.ToString(format_sotien);
			}
			catch{}
		}

		private void butHuy_Click(object sender, System.EventArgs e)
		{
			try
			{
				if (cmbSoctg.Items.Count==0) return;
				if (bKhoaso)
				{
					MessageBox.Show("Số liệu tháng "+s_mmyy.Substring(0,2)+" năm "+s_mmyy.Substring(2,2)+" đã khóa !\nNếu cần thay đổi thì vào mục khai báo hệ thống",a.Msg);
					return;
				}
//				if (a.get_data("select * from "+user+".a_ctct"+s_mmyy.Substring(2)+" where ctgs<>0 and idct="+l_id).Tables[0].Rows.Count>0)
//				{
//					MessageBox.Show("Chứng từ "+soctg.Text+" đã lập chứng từ ghi sổ !",a.Msg);
//					return;
//				}
				if (MessageBox.Show("Đồng ý hủy số phiếu này ?",a.Msg,MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
				{
					DataRow r2;
					a.updDtsd("",s_mmyy,i_userid);
					itable = a.tableid("", "a_ctct"+s_mmyy.Substring(2));
					foreach(DataRow r1 in dtct.Rows)
					{
						a.upd_eve_tables(itable, i_userid, "del");
						a.upd_eve_upd_del(itable, i_userid, "del", a.fields("a_ctct"+s_mmyy.Substring(2), "id=" + long.Parse(r1["id"].ToString())));
						if (r1["tonghop"].ToString()=="1")
						{
							a.updSodu("a_sd",a.delete,s_mmyy,long.Parse(nhom.SelectedValue.ToString()),long.Parse(chuong.SelectedValue.ToString()),l_hopdong,
								long.Parse(r1["lk"].ToString()),long.Parse(nghiepvu.SelectedValue.ToString()),lmadt,
								long.Parse(r1["tknoa"].ToString()),long.Parse(r1["tkcoa"].ToString()),
								long.Parse(r1["kmno"].ToString()),long.Parse(r1["kmco"].ToString()),
								long.Parse(r1["kmno2"].ToString()),long.Parse(r1["kmco2"].ToString()),
								long.Parse(r1["kmno3"].ToString()),long.Parse(r1["kmco3"].ToString()),
								long.Parse(r1["kmno4"].ToString()),long.Parse(r1["kmco4"].ToString()),
								long.Parse(r1["mtmno"].ToString()),long.Parse(r1["mtmco"].ToString()),
								long.Parse(hoatdong.SelectedValue.ToString()),decimal.Parse(r1["stien"].ToString()));
							r2=a.getrowbyid(dtht,"stk="+long.Parse(r1["tkcoa"].ToString()));
							if (r2!=null && l_iddongthoi!=0)
							{
								a.updSodu("a_sd",a.delete,s_mmyy,long.Parse(nhom.SelectedValue.ToString()),long.Parse(chuong.SelectedValue.ToString()),l_hopdong,
									long.Parse(r1["lk"].ToString()),long.Parse(nghiepvu.SelectedValue.ToString()),lmadt,
									0,long.Parse(r2["stkch"].ToString()),0,long.Parse(r1["kmco"].ToString()),
									0,long.Parse(r1["kmco2"].ToString()),0,long.Parse(r1["kmco3"].ToString()),
									0,long.Parse(r1["kmco4"].ToString()),0,long.Parse(r1["mtmco"].ToString()),
									long.Parse(hoatdong.SelectedValue.ToString()),decimal.Parse(r1["stien"].ToString()));
							}
							if (r1["thangqt"].ToString()!="")
							{
								a.updSodu("a_sdc",a.delete,r1["thangqt"].ToString()+s_mmyy.Substring(2),long.Parse(nhom.SelectedValue.ToString()),long.Parse(chuong.SelectedValue.ToString()),
									l_hopdong,long.Parse(r1["lk"].ToString()),
									long.Parse(nghiepvu.SelectedValue.ToString()),lmadt,long.Parse(r1["tknoa"].ToString()),
									long.Parse(r1["tkcoa"].ToString()),
									long.Parse(r1["kmno"].ToString()),long.Parse(r1["kmco"].ToString()),
									long.Parse(r1["kmno2"].ToString()),long.Parse(r1["kmco2"].ToString()),
									long.Parse(r1["kmno3"].ToString()),long.Parse(r1["kmco3"].ToString()),
									long.Parse(r1["kmno4"].ToString()),long.Parse(r1["kmco4"].ToString()),
									long.Parse(r1["mtmno"].ToString()),long.Parse(r1["mtmco"].ToString()),
									long.Parse(hoatdong.SelectedValue.ToString()),decimal.Parse(r1["stien"].ToString()));
								if (r2!=null && l_iddongthoi!=0)
								{
									a.updSodu("a_sdc",a.delete,r1["thangqt"].ToString()+s_mmyy.Substring(2),long.Parse(nhom.SelectedValue.ToString()),long.Parse(chuong.SelectedValue.ToString()),
										l_hopdong,long.Parse(r1["lk"].ToString()),
										long.Parse(nghiepvu.SelectedValue.ToString()),lmadt,0,long.Parse(r2["stkch"].ToString()),
										0,long.Parse(r1["kmco"].ToString()),0,long.Parse(r1["kmco2"].ToString()),
										0,long.Parse(r1["kmco3"].ToString()),0,long.Parse(r1["kmco4"].ToString()),
										0,long.Parse(r1["mtmco"].ToString()),
										long.Parse(hoatdong.SelectedValue.ToString()),decimal.Parse(r1["stien"].ToString()));
								}
							}
							if (a.bChophanbo(long.Parse(r1["tknoa"].ToString()),long.Parse(r1["tkcoa"].ToString())))
								a.updPhanbo("a_phanbochua",a.delete,l_id,long.Parse(r1["id"].ToString()),long.Parse(lctug.SelectedValue.ToString()),
									soctg.Text,ngayg.Text,long.Parse(r1["tknoa"].ToString()),long.Parse(r1["tkcoa"].ToString()),
									"",r1["noidung"].ToString(),1,decimal.Parse(r1["stien"].ToString()),
									long.Parse(nghiepvu.SelectedValue.ToString()),s_mmyy,i_userid);
						}
					}
					itable = a.tableid("", "a_ct"+s_mmyy.Substring(2));
					a.upd_eve_tables(itable, i_userid, "del");
					a.upd_eve_upd_del(itable, i_userid, "del", a.fields("a_ct"+s_mmyy.Substring(2), "id=" + l_id));

					a.execute_data("delete from a_ctk"+s_mmyy.Substring(2)+" where id="+l_id);
					a.execute_data("delete from a_ctct"+s_mmyy.Substring(2)+" where idct="+l_id);
					a.execute_data("delete from a_ctbk"+s_mmyy.Substring(2)+" where id="+l_id);
					a.execute_data("delete from a_ctbkct"+s_mmyy.Substring(2)+" where id="+l_id);
					a.execute_data("delete from a_ct"+s_mmyy.Substring(2)+" where id="+l_id);
					//duyet du lieu, lay het l_iddongthoi
					r=a.getrowbyid(dtll,"id="+l_id);
					if (r!=null)
					{
						string s_soctg=r["soctg"].ToString();
						string sql="select * from "+a.user+".a_ct"+s_mmyy.Substring(2)+" where soctg like '"+s_soctg+"'";
						DataSet ds_get=new DataSet();
						ds_get=a.get_data(sql);
						if(ds_get!=null && ds_get.Tables[0].Rows.Count!=0)
							foreach(DataRow rs in ds_get.Tables[0].Rows)
							{
								l_iddongthoi=long.Parse(rs["iddongthoi"].ToString().Trim());
								if (l_iddongthoi!=0)
								{
									a.execute_data("delete from a_ctk"+s_mmyy.Substring(2)+" where id="+l_iddongthoi);
									a.execute_data("delete from a_ctct"+s_mmyy.Substring(2)+" where idct="+l_iddongthoi);
									a.execute_data("delete from a_ctbk"+s_mmyy.Substring(2)+" where id="+l_iddongthoi);
									a.execute_data("delete from a_ctbkct"+s_mmyy.Substring(2)+" where id="+l_iddongthoi);
									a.execute_data("delete from a_ct"+s_mmyy.Substring(2)+" where id="+l_iddongthoi);
								}
							}
					}			
					if (l_hopdong!=0)
					{
						a.execute_data("delete from "+user+".a_theodoihdct where id="+l_hopdong+" and so='"+soctg.Text+"' and to_char(ngay,'dd/mm/yyyy')='"+ngayg.Text+"'");
						if (s_mmyyhd!="") a.execute_data("delete from "+user+"d"+s_mmyyhd+".d_thanhtoanct where id="+l_hopdong+" and so='"+soctg.Text+"' and to_char(ngay,'dd/mm/yyyy')='"+ngayg.Text+"'");
						decimal so=getsotien(0);
						a.execute_data("update "+user+".a_theodoihd set stdatra="+so+" where id="+l_hopdong);
						if (s_mmyyhd!="") a.execute_data("update "+user+"d"+s_mmyyhd+".d_thanhtoanct set datra="+so+" where id="+l_hopdong);
					}
					a.delrec(dtll,"id="+l_id);
					cmbSoctg.Refresh();
					if (cmbSoctg.Items.Count>0) l_id=long.Parse(cmbSoctg.SelectedValue.ToString());
					else l_id=0;
					load_head();
				}
			}
			catch{}
		}

		private void tongcong()
		{
			try
			{
				decimal _sotien=0,_nguyente=0;
				foreach(DataRow r1 in dtct.Rows)
				{
					_sotien+=decimal.Parse(r1["stien"].ToString());
					_nguyente+=decimal.Parse(r1["nguyente"].ToString());
				}
				zstien.Text=_sotien.ToString(format_sotien);
				znguyente.Text=_nguyente.ToString(format_sotien);
			}
			catch{}
		}


		private void butIn_Click(object sender, System.EventArgs e)
		{	
			if (lctug.SelectedIndex!=-1 && l_id!=0)
			{
				DataSet dsxml=new DataSet();				
				string tenfile=dtloai.Rows[lctug.SelectedIndex]["tenreport"].ToString();
				string maso=dtloai.Rows[lctug.SelectedIndex]["maso"].ToString();
				if (tenfile!="")
				{
					switch (int.Parse(dtloai.Rows[lctug.SelectedIndex]["loai"].ToString()))
					{
						case 3: dsxml=a.lenhchi(s_mmyy,l_id);break;
						case 4: dsxml=a.phieuthuchi(s_mmyy,l_id);break;
						default : dsxml=a.phieulinh(s_mmyy,l_id);break;
					}
					if (chkXml.Checked)
					{
						if (!System.IO.Directory.Exists("..\\xml")) System.IO.Directory.CreateDirectory("..\\xml");
						dsxml.WriteXml("..\\xml\\"+tenfile+".xml",XmlWriteMode.WriteSchema);
					}
//					if(maso=="05")
//					{
//						frmReport f=new frmReport(a,dsxml,dtloai.Rows[lctug.SelectedIndex]["ten"].ToString(),tenfile+".rpt");
//						f.ShowDialog();
//						frmReport k=new frmReport(a,dsxml,dtloai.Rows[lctug.SelectedIndex]["ten"].ToString(),"rC204NSkt.rpt");
//						k.ShowDialog();
//
//					}
//					else
//					{
						frmReport f=new frmReport(a,dsxml,dtloai.Rows[lctug.SelectedIndex]["ten"].ToString(),tenfile+".rpt");
						f.ShowDialog();
//					}
				}
			}
		}

		private void Filter_stk(string ma,LibList.List list)
		{
			try
			{
				CurrencyManager cm= (CurrencyManager)BindingContext[list.DataSource];
				DataView dv=(DataView)cm.List;
				sql="stk like '"+ma.Trim()+"%' or ttk like '%"+ma.Trim()+"%'";
				dv.RowFilter=sql;
			}
			catch{}
		}

		private void find_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==find) RefreshChildren(find.Text);
		}

		private void RefreshChildren(string text)
		{
			try
			{
				CurrencyManager cm= (CurrencyManager)BindingContext[cmbSoctg.DataSource];
				DataView dv=(DataView)cm.List;			
				sql="soctg like '%"+text.Trim()+"%'";
				dv.RowFilter=sql;
				if(cmbSoctg.SelectedIndex>=0)	l_id=long.Parse(cmbSoctg.SelectedValue.ToString());
				else l_id=0;
				load_head();
			}
			catch(Exception ex){MessageBox.Show(ex.Message);}
		}

		private void find_Enter(object sender, System.EventArgs e)
		{
			find.Text="";
		}

		private void butFind_Click(object sender, System.EventArgs e)
		{
			/*frmTimthuoc f=new frmTimthuoc(d,s_mmyy,s_loai,i_nhom,i_userid,bAdmin);
			f.ShowDialog();*/
		}

		private void lctug_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==lctug) sophieu();
		}

		private void hoatdong_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter) SendKeys.Send("{Tab}");		
		}

		private void loaidt_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==loaidt) load_dt();
		}

		private void madt_Validated(object sender, System.EventArgs e)
		{
			sql="mavt='"+madt.Text+"'";
			if (loaidt.SelectedIndex!=0) sql+=" and loaidt="+int.Parse(loaidt.SelectedValue.ToString());
			DataRow r=a.getrowbyid(dtdt,sql);
			if (r!=null)
			{
				tendt.Text=r["tendt"].ToString();
				diachi.Text=r["diachi"].ToString();
				sotk.Text=r["sotaikhoan"].ToString();
			}
			else madt.Text=tendt.Text=diachi.Text=sotk.Text="";
		}

		private void listdt_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				try
				{
					sql="mavt='"+madt.Text+"'";
					if (loaidt.SelectedIndex!=0) sql+=" and loaidt="+int.Parse(loaidt.SelectedValue.ToString());
					DataRow r=a.getrowbyid(dtdt,sql);
					if (r!=null)
					{
						diachi.Text=r["diachi"].ToString();
						sotk.Text=r["sotaikhoan"].ToString();
						tknoa.Focus();
					}
				}
				catch{}		
			}
		}

		private void tknoa_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==tknoa)
			{
				Filter_stk(tknoa.Text,liststk);
				liststk.BrowseToDmtk(tknoa,ttknoa,tkcoa,tknoa.Location.X,tknoa.Location.Y+tknoa.Height,tknoa.Width+ttknoa.Width+2,tknoa.Height,100);
			}
		}

		private void tknoa_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) liststk.Focus();
			else if (e.KeyCode==Keys.Enter)
			{
				if (liststk.Visible)	liststk.Focus();
				else SendKeys.Send("{Tab}");
			}
			else if (e.KeyCode==Keys.Escape) liststk.Hide();
		}

		private void tknoa_Validated(object sender, System.EventArgs e)
		{
			DataRow r=a.getrowbyid(dttk,"stk='"+tknoa.Text+"'");
			if (r!=null)
			{
				ttknoa.Text=r["ttk"].ToString();
				load_sotk(tknoa.Text,sotkno,tennhno);
			}
			else ttknoa.Text=sotkno.Text=tennhno.Text="";
		}

		private void tkcoa_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==tkcoa)
			{
				Filter_stk(tkcoa.Text,liststk);
				liststk.BrowseToDmtk(tkcoa,ttkcoa,tt,tkcoa.Location.X,tkcoa.Location.Y+tkcoa.Height,tkcoa.Width+ttkcoa.Width+2,tkcoa.Height,100);
			}
		}

		private void tkcoa_Validated(object sender, System.EventArgs e)
		{
			DataRow r=a.getrowbyid(dttk,"stk='"+tkcoa.Text+"'");
			if (r!=null)
			{
				ttkcoa.Text=r["ttk"].ToString();
				load_sotk(tkcoa.Text,sotkco,tennhco);
			}
			else ttkcoa.Text=sotkco.Text=tennhco.Text="";
		}

		private void tkno_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==tkno)
			{
				Filter_stk(tkno.Text,listtkno);
				if (mtmno.Enabled)
					listtkno.BrowseToDmtk(tkno,ttkno,mtmno,tkno.Location.X,tkno.Location.Y+tkno.Height,tkno.Width+ttkno.Width+2,tkno.Height,100);
				else if (kmno.Enabled)
					listtkno.BrowseToDmtk(tkno,ttkno,kmno,tkno.Location.X,tkno.Location.Y+tkno.Height,tkno.Width+ttkno.Width+2,tkno.Height,100);
				else
					listtkno.BrowseToDmtk(tkno,ttkno,tkco,tkno.Location.X,tkno.Location.Y+tkno.Height,tkno.Width+ttkno.Width+2,tkno.Height,100);
			}
		}

		private void tkno_Validated(object sender, System.EventArgs e)
		{
			DataRow r=a.getrowbyid(dttk,"stk='"+tkno.Text+"'");
			ttkno.Text=(r!=null)?r["ttk"].ToString():"";	
			load_mtm(tkno.Text,mtmno,kmno);
			load_mapt();
			//if (listtkno.Visible) listtkno.Hide();
		}

		private void tkco_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==tkco)
			{
				Filter_stk(tkco.Text,listtkco);
				if (mtmco.Enabled)
					listtkco.BrowseToDmtk(tkco,ttkco,mtmco,tkco.Location.X,tkco.Location.Y+tkco.Height,tkco.Width+ttkco.Width+2,tkco.Height,100);
				else if (kmco.Enabled)
					listtkco.BrowseToDmtk(tkco,ttkco,kmco,tkco.Location.X,tkco.Location.Y+tkco.Height,tkco.Width+ttkco.Width+2,tkco.Height,100);
				else
					listtkco.BrowseToDmtk(tkco,ttkco,noidung,tkco.Location.X,tkco.Location.Y+tkco.Height,tkco.Width+ttkco.Width+2,tkco.Height,100);
			}
		}

		private void tkco_Validated(object sender, System.EventArgs e)
		{
			DataRow r=a.getrowbyid(dttk,"stk='"+tkco.Text+"'");
			ttkco.Text=(r!=null)?r["ttk"].ToString():"";
			load_mtm(tkco.Text,mtmco,kmco);
			load_mapt();
			//if (listtkco.Visible) listtkco.Hide();
		}

		private void load_mtm(string stk,TextBox txt,ComboBox cb)
		{
			cb.Enabled=txt.Enabled=false;
			DataTable tmp;
			DataRow r=a.getrowbyid(dttk,"stk='"+stk+"'");
			if (r!=null)
			{
				if (int.Parse(r["mlns"].ToString())==1 || int.Parse(r["ctmlns"].ToString())==1)
				{
					sql="select a.stk,a.ttk,a.id,b.tennhom ";
					sql+="from a_dmch a left join a_dmnhom b on a.nhmuc=b.id ";
					if (int.Parse(r["ctmlns"].ToString())==1) sql+=" where a.cd in (1,2) and a.sudung=1";//a.c=1
					else sql+=" where a.cd=3 and a.sudung=1";//a.sp=4
					sql+=" order by a.cc";
					tmp=a.get_data(sql).Tables[0];
					listmtm.DataSource=tmp;
					if (butLuu.Enabled) 
					{
						txt.Enabled=tmp.Rows.Count>0;
						if (txt.Enabled)
						{
							listtkco.Hide();
							listtkno.Hide();
							txt.Focus();
						}
					}
				}
				sql="select * from a_dmkhoanmuc where loaikm="+int.Parse(r["loaikm"].ToString())+" and sudung=1 order by stt";
				tmp=a.get_data(sql).Tables[0];
				cb.DataSource=tmp;
				if (cb.Name=="kmno")
				{
					sql="select * from a_dmkhoanmuc where loaikm="+int.Parse(r["loaikm2"].ToString())+" and sudung=1 order by stt";
					kmno2.DataSource=a.get_data(sql).Tables[0];
					sql="select * from a_dmkhoanmuc where loaikm="+int.Parse(r["loaikm3"].ToString())+" and sudung=1 order by stt";
					kmno3.DataSource=a.get_data(sql).Tables[0];
					sql="select * from a_dmkhoanmuc where loaikm="+int.Parse(r["loaikm4"].ToString())+" and sudung=1 order by stt";
					kmno4.DataSource=a.get_data(sql).Tables[0];
				}
				else if (cb.Name=="kmco")
				{
					sql="select * from a_dmkhoanmuc where loaikm="+int.Parse(r["loaikm2"].ToString())+" and sudung=1 order by stt";
					kmco2.DataSource=a.get_data(sql).Tables[0];
					sql="select * from a_dmkhoanmuc where loaikm="+int.Parse(r["loaikm3"].ToString())+" and sudung=1 order by stt";
					kmco3.DataSource=a.get_data(sql).Tables[0];
					sql="select * from a_dmkhoanmuc where loaikm="+int.Parse(r["loaikm4"].ToString())+" and sudung=1 order by stt";
					kmco4.DataSource=a.get_data(sql).Tables[0];
				}
				if (butLuu.Enabled)
				{
					cb.Enabled=tmp.Rows.Count>0;
					if (cb.Name=="kmno")
					{
						kmno2.Enabled=kmno2.Items.Count>0;
						kmno3.Enabled=kmno2.Items.Count>0;
						kmno4.Enabled=kmno4.Items.Count>0;
					}
					else if (cb.Name=="kmco")
					{
						kmco2.Enabled=kmco2.Items.Count>0;
						kmco3.Enabled=kmco2.Items.Count>0;
						kmco4.Enabled=kmco4.Items.Count>0;
					}
					//if (cb.Name=="kmno") kmno2.Enabled=kmno3.Enabled=kmno4.Enabled=cb.Enabled;
					//else if (cb.Name=="kmco") kmco2.Enabled=kmco3.Enabled=kmco4.Enabled=cb.Enabled;
					if (!txt.Enabled && cb.Enabled)
					{
						listtkco.Hide();
						listtkno.Hide();
						cb.Focus();
					}
				}
			}			
		}

		private void mtmno_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==mtmno)
			{
				Filter_mtm(mtmno.Text);
				if (kmno.Enabled)
					listmtm.BrowseToDmtk(mtmno,stemp,kmno,mtmno.Location.X,mtmno.Location.Y+mtmno.Height,mtmno.Width+kmno.Width+55,mtmno.Height,100);
				else
					listmtm.BrowseToDmtk(mtmno,stemp,tkco,mtmno.Location.X,mtmno.Location.Y+mtmno.Height,mtmno.Width+kmno.Width+55,mtmno.Height,100);
			}		
		}

		private void mtmno_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listmtm.Focus();
			else if (e.KeyCode==Keys.Enter)
			{
				if (listmtm.Visible)	listmtm.Focus();
				else SendKeys.Send("{Tab}");
			}
			else if (e.KeyCode==Keys.Escape) listmtm.Hide();
		}
		private void Filter_mtm(string ma)
		{
			try
			{
				CurrencyManager cm= (CurrencyManager)BindingContext[listmtm.DataSource];
				DataView dv=(DataView)cm.List;
				sql="stk like '"+ma.Trim()+"%' or ttk like '%"+ma.Trim()+"%'";
				dv.RowFilter=sql;
			}
			catch{}
		}

		private void listtkno_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				try
				{
					tkno_Validated(sender,e);
					listtkno.Hide();
					if (mtmno.Enabled) mtmno.Focus();
				}
				catch{}		
			}		
		}

		private void listtkco_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				try
				{
					tkco_Validated(sender,e);
					listtkco.Hide();
				}
				catch{}		
			}	
		}

		private void tkno_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listtkno.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listtkno.Visible)	listtkno.Focus();
				else SendKeys.Send("{Tab}");
			}		
			else if (e.KeyCode==Keys.Escape) listtkno.Hide();
		}

		private void tkco_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listtkco.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listtkco.Visible)	listtkco.Focus();
				else SendKeys.Send("{Tab}");
			}				
			else if (e.KeyCode==Keys.Escape) listtkco.Hide();
		}

		private void mtmco_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==mtmco)
			{
				Filter_mtm(mtmco.Text);
				if (kmco.Enabled)
					listmtm.BrowseToDmtk(mtmco,stemp,kmco,mtmco.Location.X,mtmco.Location.Y+mtmco.Height,mtmco.Width+kmco.Width+55,mtmco.Height,100);
				else
					listmtm.BrowseToDmtk(mtmco,stemp,noidung,mtmco.Location.X,mtmco.Location.Y+mtmco.Height,mtmco.Width+kmco.Width+55,mtmco.Height,100);
			}				
		}

		private void noidunga_Validated(object sender, System.EventArgs e)
		{
			if (noidunga.Text!="" && noidung.Text=="") noidung.Text=noidunga.Text;
		}

		private void load_mapt()
		{
			DataTable tmp=a.getPhantich(tkno.Text,mtmno.Text,tkco.Text,mtmco.Text).Tables[0];
            mapt.DataSource=tmp;
			mapt.Enabled=tmp.Rows.Count>0 && butLuu.Enabled;
			if (butLuu.Enabled)
			{
				if (chucnang!=1) tonghop.Checked=!(tkno.Text.IndexOf("111")!=-1 || tkco.Text.IndexOf("111")!=-1);
				if (chucnang!=1 && chucnang!=2) tonghop.Checked=!(tkno.Text.IndexOf("112")!=-1 || tkco.Text.IndexOf("112")!=-1);
			}
		}

		private void mtmco_Validated(object sender, System.EventArgs e)
		{
			load_mapt();
		}

		private void listmtm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				try
				{
					mtmco_Validated(sender,e);
				}
				catch{}		
			}			
		}

		private void mtmno_Validated(object sender, System.EventArgs e)
		{
			load_mapt();
		}

		private void ngoaite_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==ngoaite) load_tygia();
		}

		private void load_tygia()
		{
			if (ngoaite.SelectedIndex!=-1)
			{
				tygia.Text=dtnt.Rows[ngoaite.SelectedIndex]["tygia"].ToString();
				decimal tg=(tygia.Text!="")?decimal.Parse(tygia.Text):0;
				stien.Enabled=tg==1;
				nguyente.Enabled=tg!=1;
				if (!nguyente.Enabled) nguyente.Text="";
				else
				{
					decimal nt=(nguyente.Text!="")?decimal.Parse(nguyente.Text):0;
					if (nt!=0)
					{
						decimal st=(nguyente.Text!="")?decimal.Parse(nguyente.Text)*tg:0;
						stien.Text=st.ToString(format_sotien);
					}
				}
			}
		}

		private void liststk_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				try
				{
					if (tknoa.Text!="") load_sotk(tknoa.Text,sotkno,tennhno);
					if (tkcoa.Text!="") load_sotk(tkcoa.Text,sotkco,tennhco);
					liststk.Hide();
				}
				catch{}		
			}			
		}

		private void butHD_Click(object sender, System.EventArgs e)
		{
			sql="mavt='"+madt.Text+"'";
			if (loaidt.SelectedIndex!=0) sql+=" and loaidt="+int.Parse(loaidt.SelectedValue.ToString());
			DataRow r=a.getrowbyid(dtdt,sql);
			if (r!=null)
			{
				frmTheodoihd f=new frmTheodoihd(a,long.Parse(r["id"].ToString()),r["tendt"].ToString());
				f.ShowDialog();
				if (bNew)
				{
					l_hopdong=f.id;hopdong.Text=f.sohd;s_mmyyhd=f.mmyy;decimal conlai=f.conlai;
					if (conlai!=0)
					{
						decimal st=(stien.Text!="")?decimal.Parse(stien.Text):0;
						if (st==0) stien.Text=conlai.ToString(format_sotien);
					}
				}
				tkno.Focus();
			}
			else
			{
				MessageBox.Show("Chọn đối tượng khách hàng !",a.Msg);
				return;
			}
		}

		private void frmNhapng_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.F3 && butHD.Enabled) butHD_Click(sender,e);
		}
		public bool timtkdt_ng(string mang,string s_tkss)
		{			
			string[] mangstk = mang.Split(',');
			for(int i=0;i<mangstk.Length;i++)
			{
				if(s_tkss.Equals(mangstk[i].ToString()))
					return true;
			}
			return false;
		}
	}
}

